Authenticate channel

Initialize

To initialize the Proto Android SDK, complete the following steps:

  1. Under the SETTINGS tab, copy the GATEWAY_ID (Channel ID).
948
  1. After the Gradle sync is finished with Proto dependency, you can initialize the SDK by calling the below method:
    Proto.init(this, GATEWAY_ID);

πŸ“˜

Note

By default, the Proto Android SDK connect to the production API endpoint.

  1. If you want to use the development API endpoint, call two APIs below after initializing the SDK:
    Proto.getInstance(this).setAuthenticationApiEndpoint(BuildConfig.DEV_BASE_AUTH_ENDPOINT);
    Proto.getInstance(this).setMessageApiEndpoint(BuildConfig.DEV_BASE_MSG_ENDPOINT);
  1. The BuildConfig is imported from the following cx.proto.sdk packages:

AUTHENTICATION_ENDPOINT:

  • Development environment: cx.proto.sdk.BuildConfig.DEV_BASE_AUTH_ENDPOINT
  • Production environment: cx.proto.sdk.BuildConfig.PROD_BASE_AUTH_ENDPOINT

MESSAGING_ENDPOINT:

  • Development environment: cx.proto.sdk.BuildConfig.DEV_BASE_MSG_ENDPOINT
  • Production environment: cx.proto.sdk.BuildConfig.PROD_BASE_MSG_ENDPOINT
  1. You can initialize the Proto SDK in the onCreate() function of your Activity, but ensure that it is initialized before accessing any method from the SDK

Authenticate

If you want to reuse Proto User Interface with full functionality without the need to implement the API yourself, you can skip to this section.

To authenticate the Proto Android SDK, complete the following steps:

  1. Authenticate the user to get the access token in order to use other mobile APIs:
PTUserService.getInstance().authenticateUser(new ProtoApiCallback<AuthResponse>() {
            @Override
            public void onComplete(@Nullable AuthResponse data) {

            }

            @Override
            public void onError(String errorMessage) {
                
            }
        });
  1. Get the User ID:
    String userId = PTUserService.getInstance().getUserId();
  1. Get the access token:
    String accessToken = PTUserService.getInstance().getAccessToken();
  1. Get the gateway ID:
    String gatewayId = Proto.getInstance().getGatewayId();
  1. Get the Firebase device token:
    String firebaseToken = Proto.getInstance().getFirebaseToken();

πŸ“˜

Note

By default, the Firebase Service will generate a Device ID when the app first starts.


What’s Next