如何从Intent中在默认文件应用程序中打开DCIM/Camera文件夹 [英] How to open DCIM/Camera folder in default Files app from intent

查看:246
本文介绍了如何从Intent中在默认文件应用程序中打开DCIM/Camera文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个同时接收前置摄像头和后置摄像头图像/视频的摄像头应用程序,并且我不希望每个文件在摄像头"预览中显示单独的缩略图.

I am making a camera app which takes both front camera and back camera images/video and I do not want individual thumbnails on the Camera preview for each file.

我要打开"/storage/emulated/0/DCIM/Camera"文件夹,然后使用ACTION_GET_CONTENT打开无法打开的照片/视频,因为它选择图像并按照此处的尝试退出文件"应用程序-

I want to open "/storage/emulated/0/DCIM/Camera" folder using the Files app and further open the photo/video which is not possible with ACTION_GET_CONTENT as it selects the image and exits the Files app as tried here -

    val intent = Intent(Intent.ACTION_GET_CONTENT)
    val uri: Uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).path.toString() + "/Camera")
    intent.setDataAndType(uri, "*/*")
    startActivity(Intent.createChooser(intent, "Open folder"))

我也尝试了ACTION_VIEW,但它并不特定于一个文件夹,而是按照此处的尝试打开显示所有媒体的图库-

I tried ACTION_VIEW too, but it is not specific to one folder and opens the gallery showing all media as tried here -

    val intent = Intent()
    intent.action = Intent.ACTION_VIEW
    intent.type = "image/*"
    intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
    startActivity(intent)

图片/*"在我的画廊中也显示图像和视频,这很好.当"*/*"使用我们也可以使用文件"应用程序,但它会打开下载"文件夹.我发现一种解决方案只能在此处尝试使用ES Explorer-

"image/*" shows images and videos too in the gallery for me which is good. When "*/*" is used we can use the Files app too but it opens the downloads folder. One solution I found works only with ES Explorer as tried here -

    val uri: Uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).path.toString() + "/Camera")
    val intent = Intent(Intent.ACTION_VIEW)
    intent.setDataAndType(uri, "resource/folder")
    startActivity(intent)

这是由于资源/文件夹"不支持导致崩溃.更改资源/文件夹";改为"*/*"使文件"应用程序打开下载"文件夹,并挂起照片"应用程序.

This is due to "resource/folder" not supported leading to a crash. Changing "resource/folder" to "*/*" makes Files app open the downloads folder and Photos app to hang.

图库似乎可以通过存储桶来做到这一点,但这也不是通用的.

It seems gallery can do it via buckets, but it too is not universal.

我并没有要求太多,只是显示我的Camera文件夹,从中可以打开并查看任何照片/视频.

I am not asking for much, just to display my Camera folder from where I can open and view any photo/video.

推荐答案

要从特定文件夹开始打开文件"应用,您可以使用以下代码,但可悲的是仅适用于Android 11设备.

To open the Files app starting with a certain folder you can use below code but only for Android 11 devices sadly.

//String scheme = "content://com.android.externalstorage.documents/document/primary%3APictures";
//String scheme = "content://com.android.externalstorage.documents/document/primary%3ADownload";
//String scheme = "content://com.android.externalstorage.documents/document/10F9-2E19%3ADownload";
String scheme = "content://com.android.externalstorage.documents/document/primary%3ADCIM%2FCamera";

Uri uri = Uri.parse(scheme);

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setDataAndType(uri, "vnd.android.document/root"); 

startActivity(intent );

Toast.makeText(context, "Files app opening in:\n\n" + uri.toString(), Toast.LENGTH_LONG).show();

                

这篇关于如何从Intent中在默认文件应用程序中打开DCIM/Camera文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆