Android

Implementing Chrome Custom Tabs for GMetri Experiences

To run GMetri experiences inside your application, implement the following steps:

  1. Download the android class files from this link. Chrome Custom Tabs
  2. Extract and add the files to your Android project and change the package name to match your project's.
  3. Add the Chrome custom tabs and JWT dependencies to your app's build environment. Following is an example of gradle build dependencies:
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support:customtabs:26.1.0'
        api 'io.jsonwebtoken:jjwt-api:0.11.0'
        runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.0'
        runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.11.0') {
            exclude group: 'org.json', module: 'json' //provided by Android natively
        }
    }
    

Information on how to install dependencies for other build systems are in the links below:

  1. Chrome custom tabs
  2. JWT

The downloaded zip contains 2 files: ChromeCustomTabsJwt.java and ServiceConnectionCallback.java. These files together provide the interface for chrome custom tabs to run GMetri experiences.

The class ChromeCustomTabsJwt.java implements 2 public methods:

  1. initialize(String viewerIdentifier, String apiKey, String url, Context context)
  2. launch()

Arguments:

  1. viewerIdentifier - This is a JSON string containing information for the viewer
  2. apiKey - A unique key generated for GMetri experiences.
  3. url - Url of the experience

An example implementation of the above classes:

  ChromeCustomTabsJwt chromeCustomTabs = new ChromeCustomTabsJwt();
  JSONObject obj = new JSONObject();
  try {
    obj.put("identifier", "test@example.com");
  } catch (JSONException e) {
    e.printStackTrace();
  }

  String apiKey = "your_secret_api_key";
  String url = "url_to_open";
  chromeCustomTabs.initialize(obj.toString(), apiKey, url, this);
  chromeCustomTabs.launch();
To add more fields to viewerIdentifier JSON object refer to this link

More about Chrome Custom Tabs

  • To enable GMetri XR experiences within an Android app, the app needs to implement the Chrome CustomTabs API as described in this article.

  • Chrome CustomTabs remove the restrictions imposed by WebViews on serving XR content. While WebViews don't share their state with the Chrome browser, ChromeCustomTabs are fully embeddable browser extensions capable of doing anything that a native Chrome browser can do.

  • Chrome CustomTabs give apps higher control over web experience and make transitions between native and web content seamless without having to resort to a WebView.

android performance


Last update: