Registration

In order for your app to show up on the SmartWatch 2 so that the user can run it, you must first register your app with the Smart Connect app on the phone or tablet.

Registration and Capabilities API

To register your SmartWatch 2 app, use the Registration and Capabilities API (Registration API for short). The Registration API is used by the host application to inform the Smart Extension APIs framework about the capabilities of SmartWatch 2. Every SmartWatch 2 app must implement this API to register the app in Smart Connect, as well as to tell the host app information about your app, such as:

  • Which Smart Extension APIs and API versions are used.
  • Your app’s icon, name, package name and other info to be displayed in Smart Connect.

You can think of the Registration API as being functionally similar to the AndroidManifest.xml in a standard Android app but for SmartWatch 2 apps instead.

The basics

To register your app, perform the following steps:

  1. Implement the Registration API code.
  2. Create a registration class.
  3. Override the methods to define the API versions used.
  4. Override the getExtensionRegistrationConfiguration() method.
  5. Define additional registration information.

Implement the code

To implement the Registration API, perform the following 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 Smart Accessories your app supports.

We will walk through each part of the SampleRegistrationInformation.java class which is included in all Smart Extensions code example projects.

Create a registration Class

First, we will create a class SampleRegistrationInformation that extends the RegistrationInformation class, using the following code snippet:

public class SampleRegistrationInformation extends RegistrationInformation
{
	…
}

Override the methods to define the API versions used

For each type of API, there are two methods that can be overridden. The first method defines the Target API version while the other method defines the Required API version. This is similar to how Android defines in the Android Manifest 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, the required Control API version must equal 2, since Layouts are not supported in version 1.

The Target API version is the highest version of the API that you would like to support. For example, if your app supports Layouts using both showBitmap() and showLayout(,) then you might want to set Required API version to 1 but Target API version to 2 and use showBitmap() in the case of version 1 and showLayout() in the case of version 2.

In the example code below, you can see how to set the version numbers. Returning 0 means that the API is not required for your app.

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

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

    @Override
    public int getRequiredSensorApiVersion() {
        return 0;
    }

Override the getExtensionRegistrationConfiguration() method

The getExtensionRegistrationConfiguration() method is where you define your SmartWatch 2 app’s icon, name, Preference Activity, package name and other details. This is done by putting key-value pairs in a ContentValues object. For example, to set your SmartWatch 2 app’s name and icon that shows up in Smart Connect, you would add:

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 key constants used here in the Registration API Reference.

Override the isDisplaySizeSupported() method

Finally, override the isDisplaySizeSupported() method to tell the Registration API which display that is supported by SmartWatch 2.

@Override
    public boolean isDisplaySizeSupported(int width, int height) {
        return ((width == SampleControlSmartWatch2.getSupportedControlWidth(mContext)
                && height == SampleControlSmartWatch2
                        .getSupportedControlHeight(mContext)) || (width == SampleControlSmartWatch
                .getSupportedControlWidth(mContext) && height == SampleControlSmartWatch
                .getSupportedControlHeight(mContext)) || (width == SampleControlSmartWirelessHeadsetPro
                .getSupportedControlWidth(mContext) && height == SampleControlSmartWirelessHeadsetPro
                .getSupportedControlHeight(mContext)));
    }

In the code above, the method has two arguments – width and height – and it checks those values against the values for each of the hardware accessories. You only need to list accessories that your app supports, so if your app is only supporting SmartWatch 2 for instance, you can omit the checks for SmartWatch and Smart Wireless Headset Pro.

Other registration information

When registering your SmartWatch 2 app, you can also tell the host app other capabilities of your app, including:

For more information about these capabilities, see the RegistrationInformation class in SmartExtensionUtils.