【问题标题】:How to check if the file has been scanned by media broadcast receiver如何检查文件是否已被媒体广播接收器扫描
【发布时间】:2015-11-23 10:45:35
【问题描述】:

我正在向媒体广播接收器发送扫描意图,以便系统“知道”图像:

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);

等待扫描完成的方法是什么?有听众吗?谢谢

【问题讨论】:

  • ACTION_MEDIA_SCANNER_FINISHED怎么样

标签: android image media broadcast scanning


【解决方案1】:

在您的情况下,您需要使用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);
                   }
                });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    相关资源
    最近更新 更多