【问题标题】:Can't see my folder or files after creating in other applications在其他应用程序中创建后看不到我的文件夹或文件
【发布时间】:2014-11-11 10:58:45
【问题描述】:

我有一个小应用程序,当我运行它时,它会在我的 SD 中创建一个文件夹,然后在该文件夹中保存一些视频

问题是应用程序完成工作并制作文件夹并保存文件,当我通过 USB 连接时,我仍然可以使用文件管理器或从我的电脑在 SD 中看到它

但是对于例如 当我启动 Whatsup 或我的画廊时,我看不到文件夹或视频!

我仍然可以使用文件管理器查看存储在 SD 中的文件夹和视频

那怎么了?为什么我想附加视频时在图库或其他程序中看不到文件夹和视频..

我为我的应用程序使用了相同的代码link 来创建文件夹并检查:

File folder = new File(Environment.getExternalStorageDirectory() + "/TollCulator");
boolean success = true;
if (!folder.exists()) {
    success = folder.mkdir();
}
if (success) {
    // Do something on success
} else {
    // Do something else on failure 
}

【问题讨论】:

    标签: android file save directory


    【解决方案1】:
    You need to Tell the media scanner about the new file so that it is immediately available to the user. 
    

    例如

    MediaScannerConnection.scanFile(this,
                new String[] { file.toString() }, null,
                new MediaScannerConnection.OnScanCompletedListener() {
            public void onScanCompleted(String path, Uri uri) {
                Log.i("ExternalStorage", "Scanned " + path + ":");
                Log.i("ExternalStorage", "-> uri=" + uri);
            }
        });
    

    【讨论】:

      【解决方案2】:

      图库使用MediaStore,WhatsApp 也可以。使用MediaScannerConnectionits scanFile() static method 安排您的文件被索引并通过MediaStore 提供,看看是否有帮助。

      【讨论】:

      • 工作谢谢!问题:我应该在活动开始时在运行时使用 MediaScannerConnection 还是在我的功能和内容加载后保留它?什么是正确的方法
      • @boudi:您需要等到文件写入所需的内容。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2020-06-29
      相关资源
      最近更新 更多