应该调用onMessageReceived时的权限拒绝

时间:2015-06-08 19:21:52

标签: android wear-os android-wear-data-api

我跟随此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>

application元素包含这个元数据元素:

<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)

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

1 个答案:

答案 0 :(得分:0)

摆脱这条线

android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
来自documentation

  

NotificationListenerService必须要求,以确保这一点   只有系统可以绑定它。