如何在android中使用intent打开内部内存中的截图文件夹



Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, READ_REQUEST_CODE);

我知道如何从图库中获取图像,但如何从内部存储访问DCIM/ScreenShot

使用ACTION_OPEN_DOCUMENT_TREE无法实现您想要的。

如果是Android Q+设备,你最多可以在主分区上打开选择器。

但是。。。对于ACTION_OPEN_DOCUMENT,您可以将用户之前选择的文件的uri作为额外内容放入您的意图中。

看一下DocumentsContract.EXTRA_INITIAL_URI

这可能会有所帮助:

Uri selectedUri = Uri.parse(context.getExternalFilesDir(
Environment.DIRECTORY_PICTURES+"/"));//make sure the path points to the exact folder where screenshot is saved as there is no fixed disrectory for screenshot
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedUri, "resource/folder");
if (intent.resolveActivityInfo(getPackageManager(), 0) != null)
{
startActivity(intent);
}
else
{
// if you reach this place, it means there is no any file 
// explorer app installed on your device
}

有一个目录DIRECTORY_SCREENSHOTS,但这需要29的最低sdk级别

@RequiresApi(api = Build.VERSION_CODES.Q)

Uri uri = Uri.parse(context.getExternalFilesDir(
Environment.DIRECTORY_SCREENSHOTS+"/"));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "resource/folder");
if (intent.resolveActivityInfo(getPackageManager(), 0) != null)
{
startActivity(intent);
}

最新更新