Media Scanner not Picking up Images on Certain Devices

416 Views Asked by At

I have an application which saves images to a directory on the sdcard which I then want to be picked up by the MediaScanner so they are displayed in the Gallery/Photo Library on the device.

My Problem

My current solution works correctly on the Galaxy S3, Galaxy Ace and the Sony Xperia U. What it doesn't work on is the HTC Hero.

The only way it updates its content is by restarting the device where as the other devices pick it up when its added due to me adding it to a content resolver. My code is shown below.

        ContentResolver cr = MyApplication.getAppContext().getContentResolver();
        ContentValues values = new ContentValues();
        values.put(Images.Media.TITLE,fileName);
        values.put(Images.Media.DISPLAY_NAME,photoName);
        values.put(Images.Media.DATE_TAKEN, currentPhoto.getTimestamp());
        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        values.put(Images.Media.ORIENTATION, rotation);
        values.put(Images.Media.LATITUDE,currentPhoto.getLatitude());
        values.put(Images.Media.LONGITUDE, currentPhoto.getLongitude());
        values.put(Images.Media.DATA,MainActivity.APP_GALLERY_STORAGE_PATH+File.separator+fileName);
        cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

My Question

How can I force a rescan or an update of the MediaScanner so that newly added images into that directory are displayed in the HTC Hero's Photo Gallery without restarting the device?

Thanks in advance

1

There are 1 best solutions below

0
On

I had the same problem for Huawei devices. Try adding

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

to the manisfest. It workied for me !!