Bear
Bear

Reputation: 5152

BroadcastReceiver permission

In the android doc of BroadcastReceiver:

android:permission The name of a permission that broadcasters must have to send a message to the broadcast receiver. If this attribute is not set, the permission set by the element's permission attribute applies to the broadcast receiver. If neither attribute is set, the receiver is not protected by a permission.

I have set a custom permission in application tag and I also have a receiver that trying to receive MEDIA_SCANNER_FINISHED broadcast. And I get the following warning message when the system trying to broadcast my listener event.

Permission Denial: broadcasting Intent {
 act=android.intent.action.MEDIA_SCANNER_FINISHED
 dat=file:///mnt/sdcard } from com.android.providers.media (pid=767,
 uid=10029) requires com.xxx.permission due to receiver
 com.xxx.myreceiver

How can I get the broadcast?

Upvotes: 0

Views: 1339

Answers (1)

biegleux
biegleux

Reputation: 13247

Make sure you have defined also scheme in data specification of an intent filter for your receiver in AndroidManifest.xml.

<receiver android:name=".YourReceiver">
    <intent-filter>
        <action android:name="android.intent.action.MEDIA_SCANNER_FINISHED" />
        <data android:scheme="file" />
    </intent-filter>
</receiver>

Upvotes: 1

Related Questions