Android Wear:聆听传入的通知 [英] Android Wear: Listen to incoming notifications

查看:89
本文介绍了Android Wear:聆听传入的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在可穿戴Android应用中侦听传入的通知?我试图实现一个 NotificationListenerService ,但是该服务的 onNotificationPosted()从未被调用:

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.");
    }
}

推荐答案

在Android Wear中无法使用NotificationListenerService,因为没有屏幕可供用户允许. 您必须在设备的应用中执行此操作,并使用可穿戴数据层API 进行Wear方面的操作.

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.

这篇关于Android Wear:聆听传入的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆