索尼的SmartWatch - 如何让主机应用程序包的名称 [英] Sony SmartWatch - how to get host app package name
问题描述
我想更新每当用户改变了窗口小部件设置的的SmartWatch部件。
我知道它可以通过发送 WIDGET_IMAGE_UPDATE_INTEN
意图来完成,但似乎我没有主机的应用程序包名称的信息(即com.sonyericsson.extras.smartwatch )。
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:目前,我在我的code硬了com.sonyericsson.extras.smartwatch名称
PS: Currently, I've hardwired the "com.sonyericsson.extras.smartwatch" name in my code.
推荐答案
每一次你的widget机正在接收来自主机应用程序的意图,主机应用程序的包名称是作为一个额外的意图。
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);
您可以在您的code以后使用存储的包名。这也是它是如何在其被存储为抽象类ExtensionService一个全局变量,其用于通过在SDK所有样品的扩展的SDK中,即在工具类进行。
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.
看看SDK的实用工具类这里
Take a look at the SDK utility classes here
这篇关于索尼的SmartWatch - 如何让主机应用程序包的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!