Android的ACTION_MEDIA_SCANNER_SCAN_FILE不显示图像,直至重新启动? [英] Android ACTION_MEDIA_SCANNER_SCAN_FILE not showing image until reboot?
问题描述
我目前正在开发一个Android应用程序,用户需要被存储在外部存储器设备上的照片,然后我想也得到了库扫描的文件到新的媒体添加到图库然而,这似乎并没有不更新,直到设备重新启动。
I am currently developing an Android Application where users take pictures which are stored in External Memory on the device then I am trying to also get the Gallery to scan the file to add the new media to the Gallery however this does not seem to update until the device reboots.
在code我现在用的就是如下:
The code I am using is as follows:
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Log.v("INFO", mCurrentPhotoPath.toString());
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
拍摄图片我的应用程序后,我可以验证它存在使用设备上的文件管理器应用程序,也记录它似乎它传递给媒体扫描仪
After taking a picture with my app I can verify it exists using a file manager app on the device and also Logging the file path it appears to be correct before passing it to Media Scanner
file:/storage/emulated/0/Pictures/JPEG_20140712_163043_1418054327.jpg
由于阿龙
推荐答案
试试这个
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" +
Environment.getExternalStorageDirectory())));
或使用 这个方法..
这篇关于Android的ACTION_MEDIA_SCANNER_SCAN_FILE不显示图像,直至重新启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!