Permission Denial: Not Allowed to Send Broadcast in Android

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED on KitKat only

It seems that google is trying to prevent this from KITKAT.

Looking at core/rest/AndroidManifest.xml you will notice that broadcast android.intent.action.MEDIA_MOUNTED is protected now. Which means it is a broadcast that only the system can send.

<protected-broadcast android:name="android.intent.action.MEDIA_MOUNTED" />

The following should work for all versions:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
final Uri contentUri = Uri.fromFile(outputFile);
scanIntent.setData(contentUri);
sendBroadcast(scanIntent);
} else {
final Intent intent = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()));
sendBroadcast(intent);
}

If the above is not working try the following:

According to this post you need another way to fix it.

Like using MediaScannerConnection or ACTION_MEDIA_SCANNER_SCAN_FILE.

MediaScannerConnection.scanFile(this, new String[] {

file.getAbsolutePath()},

null, new MediaScannerConnection.OnScanCompletedListener() {

public void onScanCompleted(String path, Uri uri)

{

}

});

Update APP automatically without user interaction facing issue== Permission Denial: not allowed to send broadcast android.intent.action.PACKAGE_ADDED

The error message you are getting pretty much tells you what the problem is. You have requested that the package installer notify you on completion by sending a broacast Intent with ACTION = android.intent.action.PACKAGE_ADDED. This broadcast Intent can only be sent by the Android framework. Regular apps cannot send this broadcast Intent.

You should use an explicit Intent, where you specify the component (package name and class name) for this purpose. You can have the package installer launch an Activity or a BroadcastReceiver for this purpose.


NOTE: Your app must be device owner to be able to do this without user interaction.

Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE

For little info:

Use this Permission first..

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

further info: Just check this conversation



Related Topics



Leave a reply



Submit