Tuesday, August 7, 2012

[android-developers] Service - SecurityException

Hello!

I have a problem with:
java.lang.SecurityException: Not allowed to start service Intent { act=my.package.TOGGLE_PLAYBACK } without permission not exported from uid 10094
 
This exception happens in MusicIntentReceiver (BroadcastReceiver) when starting service:
context.startService(new Intent(MusicService.ACTION_TOGGLE_PLAYBACK));
 
I'm using code from RandomMusicPlayer sample (http://www.androidside.com/docs/resources/samples/RandomMusicPlayer/index.html) with only difference that I'm using it in library project.

Manifest file in library project looks like that:
        <service
            android:name=".audio.MusicService"
            android:exported="false" >
            <intent-filter>
                <action android:name="my.lib.package.audio.TOGGLE_PLAYBACK" />

                <action android:name="my.lib.package.audio.PLAY" />
                ...
            </intent-filter>

        </service>
        <receiver
            android:name=".audio.MusicIntentReceiver">
            <intent-filter>
                <action android:name="android.media.AUDIO_BECOMING_NOISY" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </receiver>

Manifest file in "normal" project:
        <service
            android:name="my.lib.package.audio.MusicService"
            android:exported="false" >
            <intent-filter>
                <action android:name="my.lib.package.audio.TOGGLE_PLAYBACK" />

                <action android:name="my.lib.package.audio.PLAY" />
                ...
            </intent-filter>

        </service>
        <receiver
            android:name="my.lib.package.audio.MusicIntentReceiver">
            <intent-filter>
                <action android:name="android.media.AUDIO_BECOMING_NOISY" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </receiver>


This works fine on Android 2.3, but not on 4.1.1. I have tried a lot of combinations with exported="true", adding custom permission but can't find working combination :(
I can't understand how this security permission works, so I would be really grateful if someone could help me with that.

Thanks!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment