How to get notified of each new image being visible to the gallery app?

半城伤御伤魂 提交于 2019-12-03 02:18:43
Phil

ACTION_MEDIA_SCANNER_FINISHED is used for adding new directories to the gallery:

Broadcast Action: The media scanner has finished scanning a directory. The path to the scanned directory is contained in the Intent.mData field.

Constant Value: "android.intent.action.MEDIA_SCANNER_FINISHED"

You should use ACTION_MEDIA_SCANNER_SCAN_FILE, which is used to add new files - not just directories:

Broadcast Action: Request the media scanner to scan a file and add it to the media database. The path to the file is contained in the Intent.mData field.

Constant Value: "android.intent.action.MEDIA_SCANNER_SCAN_FILE"

You can test this Intent using the code discussed here.

Additionally, some have reportedly needed to include mime type and file extensions, such as:

<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.png" />

You may want to look into adding these to your filter as well:

com.android.camera.NEW_PICTURE
com.android.camera.NEW_VIDEO
android.hardware.action.NEW_PICTURE
android.hardware.action.NEW_VIDEO

The android.hardware.x actions are the "official" current broadcasts, but the com.android.x ones are sent by Samsung devices and older versions of Android.

i think you can acheive this using the FileObserver .

as mentioned in the documentation :

Monitors files to fire an event after files are accessed or changed by by any process on the device . Each FileObserver instance monitors a single file or directory. If a directory is monitored, events will be triggered for all files and subdirectories inside the monitored directory.

but you have to keep in mind :

If a FileObserver is garbage collected, it will stop sending events. To ensure you keep receiving events, you must keep a reference to the FileObserver instance from some other live object.

Please give me some feedback . Hope That helps .

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