【问题标题】:Open specific folder with intent on Android Java在 Android Java 上打开特定文件夹
【发布时间】:2021-12-03 03:56:28
【问题描述】:

我想用 Intent 打开一个特定的文件夹,但它只打开最近的文件,如下所示:

Recent Files

我的代码(更新):

 //path i want to open: /storage/emulated/0/Android/data/org.pytorch.demo.objectdetection/files/Pictures/saved_images

    String myDir = Environment.getExternalStorageDirectory() + "/" + "Android/data/org.pytorch.demo.objectdetection/files/Pictures/saved_images" + "/";
    Uri uri = Uri.parse(myDir);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, "*/*");
    startActivity(intent);

【问题讨论】:

  • 抱歉,Android 不支持“打开特定文件夹”。此外,file/* 不是有效的 MIME 类型,myDir 不是要解析的 Uri 的有效字符串表示形式。
  • 好的!我已经更改了“/”的类型并从 myDir 创建了一个 Uri。但它不断打开最近的文件(代码更新到现在的样子)
  • 抱歉,Android 不支持“打开特定文件夹”。
  • Open specific folder with intent on Android Java 标题错误。您的意思是:使用 ACTION_VIEW。但 ACTION_VIEW 不用于文件夹开头。

标签: java android android-intent


【解决方案1】:

在 Android 11 设备上,ACTION_VIEW 可用于让“文件”或“文档”应用在指定目录中打开。

代码之前已经发布过。

一个人只能浏览。不要选择文件夹或文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-12
    • 2013-05-06
    • 2021-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 2019-01-17
    相关资源
    最近更新 更多