Android ACTION_MEDIA_SCANNER_SCAN_FILE not showing image until reboot?

做~自己de王妃 提交于 2019-12-23 07:50:03

问题


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.

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

Thanks Aaron


回答1:


I managed to solve this. The issue was due to, where I setup the mCurrentPhotoPath. So I updated the code to use

photoFile = createImageFile();
mCurrentPhotoPath = photoFile.getAbsolutePath();



回答2:


Media Scanner take some to scan and insert show results after calling sendBroadcast you can use MediaScannerConnection method onScanCompleted and then check image in gallery. for more reference follow Link



来源:https://stackoverflow.com/questions/24714475/android-action-media-scanner-scan-file-not-showing-image-until-reboot

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