我想将一些数据(字符串)从Android应用程序发送到我的Smartwatch扩展程序。
我在主要活动中创建一个Intent并使用startService()发送它。
据我所知,我必须在扩展ExtensionService的类中覆盖onStartCommand()。
我的问题是我的扩展ControlExtension的类将如何通知此Intent?
提前致谢
答案 0 :(得分:2)
您最好的选择是使用广播接收器。在您的控件中注册接收器并过滤您发送的意图。 (而不是调用startService,你应该将你的意图作为广播发送)。
您可以使用
创建和广播您的意图Intent intent = new Intent("my.super.cool.intent.name");
sendBroadcast(intent)
然后过滤:
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("my.super.cool.intent.name");