2

I'm developing a RSS smart extension app using the Notification API. I would like to know how to get the active/inactive status of my smart extension (the first checkbox when clicking on my RSS smart extension in the SmartWatch app).

The NotificationAPI sample uses an extra Checkbox preference to start or not a service downloading data generating notifications, but I don't want to force the user to go into a sub menu and activate the download of data. If the user activates my RSS smart extension, he already expects the extension to notify him if there's some new items into the RSS.

There's a callback to know when my smart extension is correctly added to liveware/smartwatch apps (onRegisterResult), but I didn't find the callback to know if the smart extension is actually active or not.

Thanks in advance!

Jerker
  • 805
  • 4
  • 9
galex
  • 3,279
  • 2
  • 34
  • 46

1 Answers1

5

The SampleNotificationExtension of the Smart Extension SDK has been provided to give some examples on:

  • how to add/update/remove/read data to/from the Notification database that resides in the Liveware Manager application (which is the hub of the Smart Extension API) through a content provider

  • how to respond to the event that the user opens a Notification on the SmartWatch and e.g. presses the action button

In the example extension, there is a service that is feeding the Notification database each 10 seconds, which is then shown on the SmartWatch device. The on/off setting in the preference activity is just for starting and stopping the loop that feeds the database.

Ok.

So I guess you want to subscribe to RSS feeds, and when new posts arrive, you want them to be propagated to the SmartWatch. You probably need start a service, like in the example, and you probably should have the service running as long as the watch is connected to the phone. This you can specify here:

@Override
protected boolean keepRunningWhenConnected() {
    return true;
}

If you use the SmartExtension utility classes, your extension will automagically be registered and your service will be started. In the sample extension, after the extension has been registered, a check is done to see if the user has activated the extension via the preferences.

@Override
public void onRegisterResult(boolean result) {
    /.../
    boolean isActive = prefs.getBoolean(
            getString(R.string.preference_key_is_active), false);
    if (isActive) {
        startAddData();
    }
}

You could keep this if you want, but it is not required. As stated before, its just for starting and stopping the data feeding. Anyways, you could start a RSS check after registration.

If the user activates my RSS smart extension, he already expects the extension to notify him if there's some new items into the RSS.

When the service starts, you can check a delta between what is in the notification database, and what is fed from the RSS feed.

WELL, a long answer, hope it helps!

Jerker
  • 805
  • 4
  • 9
  • I used the SampleNotificationExtension as a base for my extension, which is awesome by the way (thanks for putting so much examples out there). I would like to stop the service (remove the alarm) if the user disabled the extension, even if the watch is still connected to the phone. I could reproduce the same behavior with the SampleNotificationExtension. Is there a way to know if the extension is active or not? – galex May 11 '12 at 08:49
  • 1
    Unfortunately, the activate/deactivate setting in the main preference screen of all extensions cannot be read by the extensions. It is stored and maintained in the SmartWatch host application. The "isActive" preference mentioned in my answer is local to the SampleNotificationExtension. So, basically, you cannot know if the user has deactivated your extension. Sorry, should have told this from the start. – Jerker May 11 '12 at 11:28
  • Could this come in a future version of the SDK, as an intent sent to the extension receiver? – galex May 11 '12 at 13:25
  • Let's just say that it is something that we are taking Into consideration, but I cannot say if or when. – Jerker May 11 '12 at 15:58
  • Ok, till then I'll provide an active preference as the SampleNotificationExtension does. – galex May 12 '12 at 09:38