我正在向媒体广播接收器发送扫描 Intent ,以便系统“识别”图像:
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);
等待扫描完成的方法是什么?有听众吗?谢谢
最佳答案
在您的情况下,您需要使用 MediaScannerConnection.scanFile
这会为您提供回调以监听通过 OnScanCompletedListener
方法完成的扫描操作。
例如
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);
}
});
关于android - 如何检查文件是否已被媒体广播接收器扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33869123/