应调用 onMessageReceived 时拒绝权限

Permission Denial when onMessageReceived should be called

我正在关注此 tutorial 并获得了 WearableListenerService。我只是实现了 onMessageReceived 方法,并没有改变任何其他东西。

该服务的条目如下所示:

<service android:name=".WearableRemoteCommandListener"
    android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="com.google.android.gms.wearable.BIND_LISTENER"></action>
    </intent-filter>
</service>

应用程序元素包含此元数据元素:

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

但是当我向可穿戴设备发送消息时,我收到了这个安全异常:

06-08 21:15:41.337      579-842/? W/ActivityManager﹕ Permission Denial: Accessing service ComponentInfo{net.bplaced.schlingel.wearabletest1/net.bplaced.schlingel.anmosela.WearableRemoteCommandListener} from pid=822, uid=10009 requires android.permission.BIND_NOTIFICATION_LISTENER_SERVICE
06-08 21:15:41.437      822-940/? W/WearableService﹕ ensureBindStarted: Permission denied connecting to net.bplaced.schlingel.anmosela.WearableRemoteCommandListener
    java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.gms.wearable.BIND_LISTENER cmp=net.bplaced.schlingel.wearabletest1/net.bplaced.schlingel.anmosela.WearableRemoteCommandListener }
            at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1793)
            at android.app.ContextImpl.bindService(ContextImpl.java:1757)
            at android.content.ContextWrapper.bindService(ContextWrapper.java:539)
            at com.google.android.gms.wearable.service.t.b(SourceFile:1157)
            at com.google.android.gms.wearable.service.t.a(SourceFile:1099)
            at com.google.android.gms.wearable.service.t.handleMessage(SourceFile:1077)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.os.HandlerThread.run(HandlerThread.java:61)

我尝试添加导出和启用的属性,重新启动可穿戴设备但异常再次发生。是否缺少权限?我的设置有什么问题?

去掉这一行

android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"

来自 documentation

Must be required by an NotificationListenerService, to ensure that only the system can bind to it.