How to force Android to re-index all the photos on the phone?

天涯浪子 提交于 2019-12-02 07:39:24

问题


I noticed something odd with the way Galaxy Nexus handles photos and file directories. I create them but Android (4.2.2) does not know they exist until you reboot. Well at least on my Nexus 4. I am creating an app and when taking a photo and storing it in Pictures it does not show on Gallery or even show up on my file explorer when you connect your phone to the computer. But when using a file explorer on the phone it finds it. When I reboot my phone it also appears. Is this specific to stock Android? I am making this assumption as it does not happen on my friend's Galaxy S3. So leading to my actual question, is there a way to force Android to re-index the files to update the info without rebooting?


回答1:


add this code after save photos in SD gallery..

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



回答2:


use

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

hope you have used this:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


来源:https://stackoverflow.com/questions/16008419/how-to-force-android-to-re-index-all-the-photos-on-the-phone

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