Phi
Phi

Reputation: 83

Trigger the rescan of MediaStore programmatically

Notice that the newly added photos(copied over using "adb push" into Pictures folder) are not included in the MediaStore Content Provider. Is there a way to trigger the rescan programmatically?

Already tried:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.parse(Environment.getExternalStorageDirectory().getPath())));

and

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/Pictures")));

which seem not work.

The broadcast Intent.ACTION_MEDIA_MOUNTED cannot be used after Android 4.4.

(1) Other than using MediaScannerWrapper to scan files myself, is there other way to programmatically trigger the rescan?

(2) Under what circumstances will the rescan happen in Android?

Upvotes: 4

Views: 2497

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006819

Already tried

You are passing a directory, not a file.

is there other way to programatically trigger the rescan?

Use MediaScannerConnection and its scanFile() method. This too requires a file AFAIK.

Upvotes: 1

Related Questions