代码之家  ›  专栏  ›  技术社区  ›  boudi

在其他应用程序中创建后无法查看我的文件夹或文件

  •  1
  • boudi  · 技术社区  · 10 年前

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

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

    但例如 当我启动Whatsup或我的Gallery时,我看不到文件夹或视频!

    我仍然可以使用文件管理器查看存储在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 
    }
    
    2 回复  |  直到 7 年前
        1
  •  2
  •   CommonsWare    10 年前

    画廊的作品来自 MediaStore ,WhatsApp也可能。使用 MediaScannerConnection its scanFile() static method 通过 媒体商店 ,看看这是否有帮助。

        2
  •  2
  •   Alex Chengalan    10 年前
    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);
            }
        });