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.
App Working Perfect with Android 4.2.2 but not with 4.4.4
You are not allowed to use the android.intent.action.MEDIA_MOUNTED
broadcast anymore on Android 4.4, it's protected. Try to use ACTION_MEDIA_SCANNER_SCAN_FILE instead.
See this question, or also this one.
Related Topics
How to Implement Export SQLite to Excel/CSV File in Android
How to Use Android Emulator for Testing Bluetooth Application
Android - Play Sound on Button Click - Null Pointer Exception
How to Read and Edit Android Calendar Events Using the New Android 4.0 Ice Cream Sandwich API
Android Logcat Logs Chatty Module Line Expire Message
Setexactandallowwhileidle - Is Not Exact as of Developer Reference
Mediastore - Uri to Query All Types of Files (Media and Non-Media)
How to Change Viewpager's Page
Android - Inner Element Must Either Be a Resource Reference or Empty
How to Include Data Files with the App's APK
Preferencefragmentcompat Has Padding on Preferencecategory That I Can't Get Rid Of
Android Ndk: Link Using a Pre-Compiled Static Library
Use Recyclerview Inside Scrollview with Flexible Recycler Item Height