我有一个 Android 应用程序(除其他外)在 Android Wear 设备上显示通知。
这是通过在 Wear 模块中扩展 WearableListenerService 的类来完成的。在 Wear 模块中,我还有一个扩展 BroadcastReceiver 的类。
这里的场景是: - 从 Android Studio 运行应用程序 - 使用电话应用程序,以便在 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;
}
.
.
.
在我的 list 文件中:
<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 操作。我检查了日志,发现 watch 上的其他监听器在重启后收到了这个事件,但我的没有。
我看过很多关于这个的帖子,例如 Android BOOT_COMPLETED not received when application is closed
我认为这可能与我的问题非常相似。
我的 android wear 应用程序没有用户可以启动的“mainactivity”——它只是监听器服务和接收器。虽然,我很快实现了一个带有启动器 Intent 的主要 Activity ,这样我就可以从 watch 上的启动器启动应用程序。这丝毫没有影响场面。 watch 重新启动后,它不会显示来 self 的应用程序的通知,直到我从 android studio 重新安装它。
所以我错过了一些重要的事情吗?当 watch 重新启动时,我的 WearableListenerService 是否应该在没有我的交互的情况下自行启动? (它没有......)或者它与这是应用程序的开发者版本有什么关系吗?
(注:我也试过先关机再开机,没区别)
最佳答案
尝试添加 <category android:name="android.intent.category.DEFAULT" />
作为你的 child <intent-filter>
关于android - Android wear 重启时我的 WearableListenerService 没有启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26887660/