2

I wonder if anyone can please shed some light on the following problem.

I am downloading images from a web site to a specific folder on my mobile Android device (HTC Desire HD). The images download perfectly (I see this using ES Explorer). They are not corrupt as I can view the images.

When my app uses a Gallery control to view the images, the Gallery is blank !!!

After playing around for some time I found that if I unmount the SD card and then remount it the images are displayed in the Gallery control.

Does anyone know why this is happening and if so is there a workaround?

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
user698564
  • 53
  • 1
  • 1
  • 7
  • if u found your answer then please let me know about this i also have same prob at :: http://stackoverflow.com/questions/21934299/gallery-item-is-not-updated-while-file-downloading – Bhanu Sharma Feb 22 '14 at 09:25

3 Answers3

4

I try this and it worked for me..hope it help others..

    MediaScannerConnection.scanFile(this, new String[] { f.getAbsolutePath()},
            null,
 new MediaScannerConnection.OnScanCompletedListener() {
    @Override
    public void onScanCompleted(String path, Uri uri) {

    }
    }); 
3

After downloading file from web just send broadcast to your device MediaScanner,

Send broadcast to MediaScannerConnection in your device like,

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

Actually, In android device gallery application scan all media files at when Remounted SDcard or at time of Reboot your device. For your requirement you have to do it manually by your code.

user370305
  • 108,599
  • 23
  • 164
  • 151
  • This search for all the images. And it involves a lot of unnecessary data processing that may be irrelevant when we have just single image to be shown up in gallery. – Rahul Rastogi Aug 21 '14 at 05:55
  • it worked but my issue is when i download first image and restart my device..it shows..and when again i download second image it does not show..even i restart my device so many times..but yet second image is not showing.. –  Feb 26 '15 at 06:10
  • @Johnson - Is your image file is exist in storage? – user370305 Feb 26 '15 at 15:01
1

Please check you have given permission

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

in your manifest file.

This will not allow your application to write images on sd card,if this is not a case than another problem might be that u do not have folder of exist in sd card.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Aamirkhan
  • 5,746
  • 10
  • 47
  • 74
  • FYI He has that permission since he can see the downloaded file FE. So your both answers does not relate to the question asked. Implementing MediaScanner would be the right way. – Yogesh Malpani Jan 10 '13 at 05:22