图像不显示在画廊了 [英] Image not showing up in gallery

查看:184
本文介绍了图像不显示在画廊了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序能够拍摄照片并将其存储到指定的文件夹。
使用ES文件浏览器,我能够确认图像已被存储在SD卡中指定文件夹。

不过,我的画廊不会立即显示出这张专辑。这将需要采取相当长的一段时间。有没有办法,我可以使检测立即使用任何方式codeS?

以下广播codeS似乎没有工作。我的画廊犯规立即执行刷新获取新创建的相册和形象。

敬请协助。谢谢!

 如果(类型== MEDIA_TYPE_IMAGE){
            媒体文件=新的文件(mediaStorageDir.getPath()+文件分割符+
            IMG _+的timeStamp +巴纽);             意图mediaScanIntent =新意图(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
             乌里contentUri = Uri.fromFile(媒体文件);
             mediaScanIntent.setData(contentUri);
             。v.getContext()sendBroadcast(mediaScanIntent);        }


解决方案

这也许直到它完成扫描需要一段时间。

如果你愿意,你至少可以当它完成通知:

  MediaScannerConnection.scanFile(
      getApplicationContext(),
      新的String [] {file.getAbsolutePath()},
      空值,
      新OnScanCompletedListener(){
         @覆盖
         公共无效onScanCompleted(字符串路径,开放的URI){
            //文件被扫描
         }
      });

有关更多信息,请阅读这里

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);

        }

解决方案

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.

这篇关于图像不显示在画廊了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆