Android Problem Collection 38: Not allowed to send broadcast Android.intent.action.MEDIA_MOUNTED

Source: Internet
Author: User

When we save the picture, we'll send a notification telling the system to sdcard it so that the other program will find it immediately.

            Intent intent = new Intent();            intent.setAction(Intent.ACTION_MEDIA_MOUNTED);            intent.setData(Uri.fromFile(Environment                    .getExternalStorageDirectory()));            sendBroadcast(intent);

But to the Android4.4 is not the spirit of the media_mounted, Google will improve the authority, so reported a following error.

W/System.err﹕java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=18338, uid=10087

In Stackoverfollow found a way to use Action_media_scanner_scan_file in the high version to notify the system to rescan files. The code is as follows:

if (Build. VERSION. SDK_int >= Build. VERSION_codes. KITKAT) {Intent mediascanintent = new Intent (Intent. ACTION_media_scanner_scan_file);Uri Contenturi = URI. FromFile(Mphotofile);//out is your output fileMediascanintent. SetData(Contenturi);Cameraactivity. this. Sendbroadcast(mediascanintent);} else {sendbroadcast (new Intent (Intent. ACTION_media_mounted, Uri. Parse("file://"+ Environment. getExternalStorageDirectory())));}} catch (FileNotFoundException e) {Log. D(TAG,"File not Found:"+ E. GetMessage());} catch (IOException e) {Log. D(TAG,"Error Accessing file:"+ E. GetMessage());}

Android Problem Collection 38: Not allowed to send broadcast Android.intent.action.MEDIA_MOUNTED

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.