简体   繁体   English

将数据从应用程序传递到控制扩展(smartwatch)

[英]pass data from app to control extension (smartwatch)

I would like to send some data (string) from Android application to my Smartwatch extension. 我想将一些数据(字符串)从Android应用程序发送到我的Smartwatch扩展程序。

I create an Intent in my Main Activity and send it using startService(). 我在主要活动中创建一个Intent,然后使用startService()发送它。

From that I understand, I have to override onStartCommand() in a class that extends ExtensionService. 据我了解,我必须在扩展ExtensionService的类中重写onStartCommand()。

My question is how my class that extends ControlExtension will be notify of this Intent ? 我的问题是,如何扩展ControlExtension的类将收到此Intent的通知?

Thanks in advance 提前致谢

Your best option is to use a broadcast receiver. 最好的选择是使用广播接收器。 Register a receiver in your control and filter for the intent you send. 在控件中注册一个接收器,并过滤发送意图。 (Instead of calling startService you should send your intent as a broadcast). (而不是调用startService,您应该以广播形式发送意图)。

You can create and broadcast your intent with 您可以创建并传播您的意图

Intent intent = new Intent("my.super.cool.intent.name");
sendBroadcast(intent)

and then filter with: 然后过滤:

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("my.super.cool.intent.name");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM