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