Scan Android SD card for new files

后端 未结 6 1747
感情败类
感情败类 2020-11-27 19:59

My app allows a user to save an image to their SD card. But I\'m not sure how to make it appear in the gallery until you unmount and remount the SD card. I have googled for

6条回答
  •  感情败类
    2020-11-27 20:29

    Use MediaScannerConnection:

    http://developer.android.com/reference/android/media/MediaScannerConnection.html

    It can be a little bit of a pain because of the multiple levels of asynchronous calls, so as of API 8 (Froyo) there is a helper function:

    http://developer.android.com/reference/android/media/MediaScannerConnection.html#scanFile(android.content.Context, java.lang.String[], java.lang.String[], android.media.MediaScannerConnection.OnScanCompletedListener)

提交回复
热议问题