Android

Last modified by editor on 2017/02/08 21:50

About

This page shows how to use the Caret Service Client API in Android application.

The example application can be downloaded from https://github.com/pomus/Caret-SampleService.

Android Service Client API usage

In order to develop your own Caret Service using the API, import the CaretApi and CaretApiConfiguration classes from the com.wallrust.service.sample.util package. Afterwards, perform the following steps:

1. Copy keys

Copy Phone Number, Service name, Service Id and Service Secret Key to fields of CaretApiConfiguration.

2. Init service

Enable Caret integration for your service:

CaretApi.appInit(new CaretApi.Callback() {
  @Override
  public void ok(String UUID) {
      // save UUID
  }
  @Override
  public void error(String error) {
      // handle error
  }
});

3. Consent

Ask Caret users for approving your service:

CaretApi.consent(thisActivity, uuid);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == CaretApi.CARET_CONSENT_REQUEST_CODE) {
      if (resultCode == RESULT_OK) {
          // consent succes
      } else {
          // consent fail
      }
  }
  super.onActivityResult(requestCode, resultCode, data);
}

4. Publish user’s status update

CaretApi.publishStatus(UUID, CaretApi.GAMING);

or

CaretApi.publishStatusWithText(UUID, CaretApi.GAMING, "Hello word");

or

CaretApi.publishStatusWithContextJSON(UUID, CaretApi.GAMING, json);

5. Publish service-off

Publish service-off, if the user leaves the application.

CaretApi.serviceOff(UUID);

6. Delete service

Delete service consent, if user wants to switch off Caret service.

CaretApi.appDelete(UUID, new CaretApi.Callback() {
  @Override
  public void ok(String result) {
      // remove UUID
  }

  @Override
  public void error(String error) {
      // handle error
  }
});
Tags:
Created by editor on 2017/02/06 07:45