Registration

The SmartConnect component displays available apps that have been extended to support SmartEyeglass. You must register your app with SmartConnect so that SmartEyeglass can show the entry card and allow the user to run it.

Registration and Capabilities API

To register your SmartEyeglass app, use the Registration and Capabilities API.

The Registration API is functionally similar to the Android manifest (AndroidManifest.xml) in a standard Android app, providing the same kind of information for a SmartEyeglass app. The Host Application uses the Registration API to inform the SmartExtension framework about the specific device capabilities that your app supports.

In every SmartEyeglass app, you must implement the Registration API to register the app in SmartConnect and provide information about the app, such as:

  • Which SmartExtension APIs and API versions your app uses. SmartConnect uses this information to determine which accessory devices your app extension is compatible with.
  • What display sizes are supported.
  • Your app’s icon, name, package name and other information to be displayed in SmartConnect and on the accessory device.

The basics

To implement the Registration and Capabilities API in your app extension, follow these general steps:

  1. Create a class that extends RegistrationInformation.
  2. Override the methods to define the API versions used.
  3. Override the getExtensionRegistrationConfiguration() method to define your app’s registration info.
  4. Override the isDisplaySizeSupported() method to define which accessories your app supports.
  5. Return an instance of RegistrationInformation in your ExtensionService class.

Below, we will walk through each part of the SampleRegistrationInformation.java class which is included in all SmartExtensions code example projects.

1. Create a registration class

First, we will create a class SampleRegistrationInformation that extends the RegistrationInformation class:

public class SampleRegistrationInformation extends RegistrationInformation
{
...
}

2. Define the compatability and API versions used

As Sony continues to develop and improve the SmartEyeglass SDK, new versions of the SmartEyeglass API are released. You should set the SmartEyeglass version compatibility requirement for your app, and also the specific versions of particular SmartExtension API components that you use.

Set SmartEyeglass API compatibility

To ensure that the version currently running on the user’s device is compatible with your app, your initialization code should set the minimum version of the SmartEyeglass API that your app requires. To do this, call the following function:

smartEyeglassControlUtils.setRequiredApiVersion(int version)

This allows the framework to warn the user if they need to install an update, and then exit gracefully from your app.

By default, the required API version is set to the highest level available in the SmartEyeglass SDK (as defined by the constant R.integer.api_version). For the best user experience, you should explicitly set it to the highest API level that you actually require for the functions that your app uses.

Check the Javadoc reference documentation to see what version is required for each function. The “since” field gives the version number in which that function was introduced.

Set SmartExtension API versions used

For each type of API (for example, Control or Sensor) available for SmartEyeglass, there are specific methods that you need to override to provide version information, if you use that functionality. For each type of API, you can define the required API version, and the target API version. This is similar to how the Android Manifest defines the minimum and target SDK versions for an app.

  • The required API version is the lowest version of the API that the accessory must support for your app to run on it. For example, if you are only using layouts for display, the required Control API version should be 4, since layouts are not supported in version 1. If you use a type of functionality, you must supply this version information.
  • The target API version is the highest version of the API that you would like to support. This specification is optional. For example, if your app uses both showBitmap() and showLayout(), then you might want to set required API version to 1 but target API version to 4. You can then use showBitmap() when running on version 1, and showLayout() when running on version 4.

This example shows how to set the version numbers. Return 0 (zero) as the required version if your app doesn’t use the API.

@Override
public int getRequiredControlApiVersion() {
    return 4;
}

@Override
public int getTargetControlApiVersion() {
    return 4;
}

@Override
public int getRequiredSensorApiVersion() {
    // Return 0 if the API is not required for your app
    return 0;
}

3. Set the configuration information

Override the getExtensionRegistrationConfiguration() method to define your app’s icon, name, Preference Activity, package name and other details.

Specify each configuration option as a key-value pair in a ContentValues object. For example, to set the name and icon that shows up in SmartConnect for your app, add values like this:

ContentValues values = new ContentValues();
values.put(Registration.ExtensionColumns.NAME, mContext.getString(R.string.extension_name));
values.put(Registration.ExtensionColumns.HOST_APP_ICON_URI, iconHostapp);
return values;

You can find a full list of the defined key constants in the API reference for Registration.ExtensionColumns.

You can also tell the Host App other capabilities of your app, such as whether your app intercepts the back button. For more information about these capabilities, see documentation for the RegistrationInformation class in SmartExtensionUtils.

4. Specify the display size

Override the isDisplaySizeSupported() method to tell the Registration API the display size of each of the accessories that you support. The framework uses this information to determine if your app can run on the display for the current accessory.

For example, this code checks the display width and height it receives for the current device against the dimensions of each target device:

@Override
public boolean isDisplaySizeSupported(int width, int height) {
    boolean isSW2 =
        (width == SampleControlSmartWatch2.getSupportedControlWidth(mContext) &&
         height == SampleControlSmartWatch2.getSupportedControlHeight(mContext));

    boolean isSEG =
        (width == HelloLayoutsSEGControl.getSupportedControlWidth(mContext) &&
         height == HelloLayoutsSEGControl.getSupportedControlHeight(mContext));

    return isSW2 || isSEG;
}

You only need to list accessories that your app supports. For example, if your app supports only SmartEyeglass, you don’t need to check against the SmartWatch 2 values.

5. Create an instance of your RegistrationInformation class

In your class that extends the ExtensionService class, override the getRegistrationInformation() method to create and return an instance of your registration class:

@Override
protected RegistrationInformation getRegistrationInformation() {
    return new SampleRegistrationInformation(this);
}

Comments 0

Sort by:

Showing 0 of 0 comments. Show all comments