2014-07-24 18 views
0

我是新来的android,我复制文件到/存储/ sdcard1从主机使用ADB推。 但无法从图库应用程序中查看文件。它通过ls命令显示,当我重新启动设备时,图库应用程序正常显示文件。但立即它不在图库中更新,那么任何人都可以帮我解决这个问题吗?图像不更新在画廊

在此先感谢

+0

你使用任何文件浏览器?这与刷新数据有关,如果你使用ES File Explorer,那么你有一个刷新按钮。点击它刷新。 – Prateek

回答

0

因为您的图库数据库未更新。

您可以运行媒体扫描仪手动

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

或用手使用

MediaStore.Images.Media.insertImage(); 

您还可以插入画廊(媒体)DB。

private Uri insertMediaStore(String dirPath, String filename, byte[] jpegByteArray) { 
    String filePath = dirPath + "/" + filename; 

    try { 
     ContentValues values = new ContentValues(); 
     values.put(Images.Media.DATE_TAKEN, new Date().getTime()); 
     values.put(Images.Media.ORIENTATION, "0"); 

     String title = filename.replace(".jpg", ""); 

     values.put(Images.Media.TITLE, title); 
     values.put(Images.Media.DISPLAY_NAME, filename); 
     values.put(Images.Media.MIME_TYPE, "image/jpeg"); 
     values.put(Images.Media.SIZE, jpegByteArray.length); 
     values.put("_data", filePath); 

     Uri uri = getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values); 
     OutputStream os = getContentResolver().openOutputStream(uri); 
     os.write(jpegByteArray); 
     os.close(); 

     Logger.info("MediaStore Inserted URI:" + uri.toString()); 

     return uri; 
    } catch(Exception ex) { 
     Logger.error(ex, "Failed to save the Bitmap file. FilePath: %s", filePath); 
    } 

    return null; 
} 

码参考:http://helloworld.naver.com/helloworld/1819

0

你必须通知媒体扫描仪捕捉到新创建的文件的元数据。像Gallery这样的应用程序在元数据数据库上工作,而不是直接在文件系统上。

以编程方式,您将使用MediaScannerConnection

由于您正在使用adb,因此您可以send a broadcast to invoke media scanner

媒体扫描程序作为引导顺序的一部分运行,所以这就是重新启动后它工作的原因。