Android Wear: Listen to incoming notifications

匿名 (未验证) 提交于 2019-12-03 02:35:01

问题:

Is it possible to listen for incoming notifications in an Wearable Android App? I have tried to implement a NotificationListenerService, but the service's onNotificationPosted() is never called:

public class MyListenerService extends NotificationListenerService {      @Override     public void onCreate() {         super.onCreate();         Log.d("NotificationListener", "This works....");     }      @Override     public void onNotificationPosted(StatusBarNotification sbn) {         Log.i("NotificationListener", "... but this method won't be called.");     } } 

回答1:

It's not possible to use a NotificationListenerService in Android Wear as there is no screen for the user to allow this. You have to do it in the device's app and to use the Wearable Data Layer API to perform the action on Wear's side.



回答2:

Try this:

adb shell settings put secure enabled_notification_listeners com.google.android.wearable.app/com.google.android.clockwork.stream.NotificationCollectorService:$YOUR_PACKAGE/$YOUR_PACKAGE.$YOUR_NOTIFICATION_LISTENER



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!