I'm sending a scan intent to media broadcast receiver so that that the image would be "known" by the system:
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(path);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
getActivity().sendBroadcast(mediaScanIntent);
What is the way to wait until the scan is completed? Any listener? Thanks
IN your case you need to use MediaScannerConnection.scanFile
which gives you a callback to listen scan action completed via OnScanCompletedListener
method.
For example
MediaScannerConnection.scanFile(
getApplicationContext(),
new String[]{file.getAbsolutePath()},
null,
new OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Log.v(TAG,
"file " + path + " was scanned seccessfully: " + uri);
}
});