【问题标题】:Android media scan not running second timeAndroid媒体扫描没有第二次运行
【发布时间】:2012-05-31 22:33:26
【问题描述】:

我正在研究一个可以扫描特定文件夹的代码,拍照时,我使用了以下代码:

Intent intent = new Intent();
intent.setType("image/*");
//intent.setAction(Intent.ACTION_GET_CONTENT);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://sdcard/ghost/" + Environment.getExternalStorageDirectory())));
startActivityForResult(
Intent.createChooser(intent, "Select Picture"), 0);

它工作正常,但是当我退出应用程序并再次启动应用程序时,没有执行扫描,可能是什么问题?

需要帮助!!!

【问题讨论】:

    标签: android path sd-card android-mediascanner


    【解决方案1】:

    而不是使用sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://sdcard/ghost/" + Environment.getExternalStorageDirectory())));

    我用过

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    

    【讨论】:

      【解决方案2】:

      这是我用来让它扫描特定文件的。

      设置文件路径
      String sdPicPath = Environment.getExternalStorageDirectory().getAbsoluteFile() + "/image.png";

      或者如果我有相册
      String sdPicPath = Environment.getExternalStorageDirectory().getAbsoluteFile() + "AlbumName/image.png";

      创建文件
      File CheckForAlbum = new File(sdAlbumPath);

      让 MediaScan 扫描特定文件。
      sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(CheckForFile1)));

      【讨论】:

        猜你喜欢
        • 2012-10-27
        • 1970-01-01
        • 1970-01-01
        • 2014-05-24
        • 2017-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多