Android Wear重新启动时,我的WearableListenerService未启动

时间:2014-11-12 13:01:46

标签: android android-intent broadcastreceiver wear-os android-service-binding

我有一个Android应用程序(除其他外)在Android Wear设备上显示通知。

这是通过让Wear模块中的类扩展WearableListenerService来完成的。在Wear模块中,我还有一个扩展BroadcastReceiver的类。

这里的情景是:   - 从Android Studio运行应用程序   - 使用电话应用程序,以便在Wear设备上显示通知   - 重新启动Wear设备

现在我想要的是,如果我让手机显示另一个通知,它应该出现在可穿戴设备上。情况并非如此,因为WearableListenerService未启动...

所以我让BroadcastManager听取ACTION_BOOT_COMPLETED事件:

@Override
public void onReceive(Context context, final Intent intent) {
    Log.d(TAG, "onReceive!");
    if(intent==null)
        return;

    if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        Log.d(TAG, "Action boot completed");
        ComponentName c = context.startService(new Intent(context, OngoingNotificationListenerService.class));
        Log.d(TAG, "returned " + c);
        return;
    }
    .
    .
    .

在我的清单文件中:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
.
.
.
<receiver android:name=".ActionsReceiver" android:enabled="true" android:exported="false">
        <intent-filter>
            <action android:name="com.XX.receiver.action_pause" />
            <action android:name="com.XX.receiver.action_resume" />
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
</receiver>

现在的问题是我的应用程序没有收到BOOT_COMPLETED操作。我检查了日志,看到手表上的其他监听器在重启后收到此事件,但不是我的。

例如,我看过几篇有关此事的帖子 Android BOOT_COMPLETED not received when application is closed

我认为这可能与我的问题非常相似。

我的android穿戴应用程序没有用户可以启动的“主动” - 它只是听众服务和接收器。虽然,我很快就用启动器意图实现了一个主要的活动,这样我就可以从手表上的启动器启动应用程序。这根本不影响情绪化。一旦手表重新启动,它将不会显示我的应用程序的通知,直到我从android studio重新安装它。

所以我错过了重要的事情吗?重启手表时,我的WearableListenerService是否应该在没有我的交互的情况下自行启动? (它没有......)或者它与应用程序的开发者版本有什么关系?

(注意:我也试过关闭然后开始 - 没有区别)

2 个答案:

答案 0 :(得分:0)

尝试添加<category android:name="android.intent.category.DEFAULT" />作为您的孩子<intent-filter>

答案 1 :(得分:0)

您需要将服务添加到您的服装模块的清单中,并将 BIND_LISTENER DATA_CHANGED操作添加到其中:

要在/前缀的路径上侦听数据项和消息,新语法如下所示(根据android tools site):

<service android:name=".ExampleWearableListenerService">
    <intent-filter>
        <action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
        <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
        <data android:scheme="wear" android:host="*" android:pathPrefix="/prefix" />
    </intent-filter>
</service>
相关问题