Permission Denial when onMessageReceived should be called

575 Views Asked by At

I'm following this tutorial and got a WearableListenerService. I just implemented the onMessageReceived method and didn't change anything else.

The entry for the service looks like this:

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

The application element contains this meta-data element:

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

But when I send a message to the wearable I get this security exception:

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)

I tried to add the exported and enabled attribute, restarted the wearable but the exception happens again. Is there a permission missing? What is wrong with my setup?

1

There are 1 best solutions below

0
On BEST ANSWER

get rid of this line

android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"

from the documentation

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