我正在构建一个Wear应用程序,它将与掌上电脑上的WearableListenerService进行通信.
但是,我想确保当应用程序在手表上启动时服务已启动并运行.
但是,我想确保当应用程序在手表上启动时服务已启动并运行.
我最初的想法是发送意图或广播消息以启动服务.
但是,我一直无法弄清楚如何让手表将其发送到配对的手持设备.
在手表方面:
- Intent intent = new Intent();
- intent.setAction("my.wearable.CONNECT");
- sendBroadcast(intent);
在手持设备方面:
- public class WearableBroadcastReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context,Intent intent) {
- Intent startServiceIntent = new Intent(context,WearableService.class);
- context.startService(startServiceIntent);
- }
- }
- <receiver android:name=".service.wearable.WearableBroadcastReceiver" >
- <intent-filter>
- <action android:name="my.wearable.CONNECT" />
- </intent-filter>
- </receiver>