Question

I have an application that makes changes to some of the files in the media folders (DCIM/Camera specifically)

After I make theses changes the application sends this broadcast in order to force the MediaScanner to run so that my changes get reflected in the Gallery app the next time it is opened.

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

This works perfect on devices running stock android. However on devices with motoblur it fails and gives me this output in the log:

Permission Denial: broadcasting Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///mnt/sdcard } from com.my.package (pid=20882, uid=10109) requires com.motorola.blur.service.blur.Permissions.INTERACT_BLUR_SERVICE due to registered receiver BroadcastFilter{40a444c8 ReceiverList{40a22888 13696 com.motorola.blur.service.blur/10023 remote:40a340b8}}

Is there some way I can use this INTERACT_BLUR_SERVICE permission? Or is there some other way I can get the Media Scanner to run on command?

Was it helpful?

Solution 2

I never found a way to trigger the media scanner. But I was pointed towards a different means of deleting the images and videos, rather than just deleting the files on the SD card, I now use a ContentResolver to delete the media.

Here is a snippet of how I've done it:

        //Uri imgUri = Uri.parse("content://android.provider.MediaStore.Images.Media");
        ContentResolver cr = getContentResolver();
        int count = cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null);
        count += cr.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null);
        Log.i(myTag, "Deleted " + count + " files from media database");

OTHER TIPS

Souldn't adding this permission in your AndroidManifest solve the problem?... like this :

<uses-permission android:name=
         "com.motorola.blur.service.blur.Permissions.INTERACT_BLUR_SERVICE"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top