1

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.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Sam Lu
  • 3,448
  • 1
  • 27
  • 39
  • 1
    I cannot edit your question due to another pending edit. I suggest that you add the `smartwatch` tag, as Sony is monitoring that for SmartWatch tech support, if I understand correctly. – CommonsWare Jun 03 '12 at 10:56

1 Answers1

3

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

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Jerker
  • 805
  • 4
  • 9
  • In the CONFIGURATION_ACTIVITY PreferenceActivity (invoked by LiveManager > Applications > my_app > Settings), I would like to update SmartWatch widget whenever user changes the settings. I try to call getIntent().getStringExtra(Widget.Intents.EXTRA_AHA_PACKAGE_NAME), but only NULL is returned. – Sam Lu Jun 04 '12 at 10:04
  • 1
    The first time your widget gets an intent from the host application, e.g. when it is created, you can store the host package name. Either store it as a global variable, or you could store it in your shared preferences. If you store it in the shared preferences, you can access it from the PreferenceActivity when you want to refresh the widget. Otherwise you could do some fancy inter-communcation between the pref.activity and your ExtensionService. – Jerker Jun 04 '12 at 11:02