【问题标题】:Open a specific folder inside gallery android在画廊 android 中打开一个特定的文件夹
【发布时间】:2015-01-28 15:16:46
【问题描述】:

我有一个相机应用程序,可以将图像保存到画廊内的单独文件夹中。 我的文件夹路径是/storage/emulated/0/Pictures/CameraExample/

当我单击按钮时,我需要打开保存图像的文件夹。我已经使用了所有可用的解决方案。

这就是我阅读路径的方式。如果我错了,请告诉我。

String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath();
        Log.d("HelperUtils . getFilePaths", "setting the path " + path);
        String targetPath = path +"/CameraExample/";

如何启动一个新的 Intent 并打开文件?

【问题讨论】:

标签: android gallery android-gallery


【解决方案1】:

您可以像这样列出目录中存在的所有文件

File[] listFile;
File file = new File(android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "CameraExample");
if (file.isDirectory()) 
        listFile = file.listFiles();

然后您可以使用GridView 或您想要的任何方式显示这些图像。

编辑: 使用意图打开文件夹

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath()
+ "/CameraExample/");
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));

【讨论】:

  • 没关系。但我需要从内置图库中打开我的文件夹。我不想创建任何 gridview,bcoz android 画廊处理一切。我只需要打开我的文件夹。
  • 为此,您需要创建一个 MediaScanner,让画廊知道要显示什么。画廊不会显示任何图像,即使它们在同一个文件夹中,除非它们被明确添加到画廊中。
  • 你能给我提供一个实现 MediaScanner 的例子吗?如果只是实现 MediaScanner ,那就足够了,还是我必须在 XML 布局文件中做额外的工作。
  • 上面的代码是打开画廊的最近图像而不是特定文件夹中的图像。实施媒体扫描仪的示例?
  • 交叉检查opend文件夹和cameraexample文件夹中的图片..应该相同
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 2012-11-05
  • 1970-01-01
  • 2021-12-03
  • 1970-01-01
相关资源
最近更新 更多