Sony SmartWatch - how to get host app package name

2019-06-03 16:15发布

问题:

I would like to update the SmartWatch widget whenever the user changes the widget settings. I know it can be done by sending an WIDGET_IMAGE_UPDATE_INTEN intent, but it seems that I don't have the information of host app package name (i.e. com.sonyericsson.extras.smartwatch).

How can I get "host app package name"?

PS: Currently, I've hardwired the "com.sonyericsson.extras.smartwatch" name in my code.

回答1:

Every time your widget extension is receiving an intent from the host application, the package name of the host app is included as an extra in the intent.

String hostAppPackageName = intent.getStringExtra(Widget.Intents.EXTRA_AHA_PACKAGE_NAME);

You could store the package name for later use in your code. This is also how it is done in the utility classes of the SDK, i.e. it is stored as a global variable in the abstract class ExtensionService, which is used by all Sample extensions in the SDK.

Take a look at the SDK utility classes here