Image not showing up in gallery

Deadly 提交于 2019-12-13 05:26:25

问题


My app is able to take a photo and stores it into a specified folder. Using ES File explorer, I'm able to confirm that the image has been stored in sd card and the specified folder.

However, my gallery is not showing this album immediately. It will need to take quite some time. Is there any ways that i can make the detection immediate using codes?

The following broadcasting codes did not seem to work. My gallery doesnt immediately do a refresh to retrieve the newly created album and image.

Kindly assist. Thanks!

if (type == MEDIA_TYPE_IMAGE){
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
            "IMG_"+ timeStamp + ".png");

             Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
             Uri contentUri = Uri.fromFile(mediaFile);
             mediaScanIntent.setData(contentUri);
             v.getContext().sendBroadcast(mediaScanIntent);

        }

回答1:


It might take some time till it finished the scanning.

If you wish, you can at least be notified when it finished:

MediaScannerConnection.scanFile(
      getApplicationContext(), 
      new String[]{file.getAbsolutePath()}, 
      null, 
      new OnScanCompletedListener() {
         @Override
         public void onScanCompleted(String path, Uri uri) {
            // file was scanned
         }
      });

for more information read here.



来源:https://stackoverflow.com/questions/15043401/image-not-showing-up-in-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!