Gigya Job Openings

Android SDK v4.x Migration Guide

Skip to end of metadata
Go to start of metadata

Description

The following guide will help you with transitioning your current application code to our new Android v4 SDK.

We recommend to take the time and read out SDK v4 implementation guide at our Android SDK v4 page.

 

Initialization & account schema definitions

Contrary to our Android SDK v3, our new SDK v4 provides both implicit and explicit initialization. In addition, one of the major changes to the SDK is the option to define your own account schema for a safer and more intuitive usage of the account response. This will impact how you must reference your SDK instance.

Example comparison:

Android SDK v3 - Initialization & referencing the Gigya interface
GSAPI.getInstance().initialize(this, "YOUR-API-KEY");
  
GSAPI.getInstance().initialize(this, "YOUR-API-KEY", "<Data_Center>");
Android SDK v4 - Initialization & referencing the Gigya interface
/*
Initializing the SDK. Account schema will be set to GigyaAccount.class.
*/
Gigya.getInstance()
    
/*
Initializing the SDK with a custom account schema.
*/
Gigya.getInstance(MyAccount::class.java)

 

Sending Requests

A major change was made on how the Android SDK will send a request to our endpoints.

The following is a representation of sending a simple request (accounts.verifyLogin) in both version of the SDK.

Android SDK v3 - Sending a request
// Step 1 - Defining request parameters
GSObject params = new GSObject();
params.put("UID", "ACCOUNT-UID");
  
// Step 2 - Defining response listener. The response listener will handle the request's response.
GSResponseListener resListener = new GSResponseListener() {
        @Override
        public void onGSResponse(String method, GSResponse response, Object context) {
            try {
                if (response.getErrorCode()==0) { // SUCCESS! response status = OK
                    System.out.println("Success in setStatus operation.");              
                } else {  // Error
                    System.out.println("Got error on setStatus: " + response.getLog());
                }
            } catch (Exception ex) {  ex.printStackTrace();  }
        }
    };
  
// Step 3 - Sending the request
String methodName = "accounts.verifyLogin";
GSAPI.getInstance().sendRequest(methodName, params, resListener, null);
Android SDK v4 - Sending an "anonymous" request.
/*
Setup a map of parameters.
*/
final Map<String,Object> params = new HashMap<>();
params.put("UID", "YOUR-ACCOUNT-UID");
    
/*
Sending "verifyLogin" REST api.
*/
final String API = "accounts.verifyLogin";
    
/*
Send a POST request. Will receive a general purpose GigyaApiResponse.class object in the success block.
*/
mGigya.send(API, params, new GigyaCallback<GigyaApiResponse>() {
    @Override
    public void onSuccess(GigyaApiResponse obj) {
        // Success
    }
   
    @Override
    public void onError(GigyaError error) {
        // Fail
    }
});
    
/*
Send a typed POST request. Will receive parsed MyAccount object in the success block.
RestAdapter.GET is also available depending on the api in question.
*/
mGigya.send(API, params, RestAdapter.POST, MyAccount.class, new GigyaCallback<MyAccount>() {
    @Override
    public void onSuccess(GigyaAccount obj) {
        // Success
    }
   
    @Override
    public void onError(GigyaError error) {
        // Fail
    }
});

 

Using Screen-Sets

The difference when using Screen-Sets between the two versions is the extension of the GigyaPluginCallback class which provides a more elaborate handling of the JS interface and the account interaction.

The following example demonstrates how to open the Default-RegistrationLogin Screen-Set.

Android SDK v3
GSObject params = new GSObject();
params.put("screenSet", "Default-RegistrationLogin");
  
GSAPI.getInstance().showPluginDialog("accounts.screenSet, params, new GSPluginListener() {
  
    @Override
    public void void onLoad(GSPluginFragment pluginFragment, GSObject event) {
    }
  
    public void onError(GSPluginFragment pluginFragment, GSObject error) {
    }
  
    void onEvent(GSPluginFragment pluginFragment, GSObject event) {
        // Events are represented within the GSObject structure.
    }
  
}, null);
Android SDK v4
/*
Showing "Registration-Login" screen-set in a dialog mode. Overriding only the onLogin method to be notified when logging in event was fired.
*/
mGigya.showScreenSets("Default-RegistrationLogin", false, null, new GigyaPluginCallback<MyAccount>() {
    
    @Override
    public void onLogin(@NonNull MyAccount accountObj) {
       // Login success.
    }
  
    /* All additional events are overload methods and are optionally available for use */
});

 

 

 

 

 

 

 

  • No labels