我需要在包含图像的内部存储中打开文件夹。
我使用以下代码。
爪哇
File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyPhotos");
Intent intent = new Intent(Intent.ACTION_VIEW);
String path =folder.getPath();
Uri myImagesdir = Uri.parse("file://" + path );
intent.setDataAndType(myImagesdir,"*/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
路径
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="images" path="Pictures" />
<external-path name="external_files" path="."/>
<external-path name="files_root" path="Android/data/${applicationId}"/> </paths>
显现
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
xml/文件路径
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="images" path="Pictures" />
<external-path name="external_files" path="."/>
<external-path name="files_root" path="Android/data/${applicationId}"/>
</paths>
错误
致命异常:主进程:android.apps.bnb.company.myphotos,PID:22482 android.os.FileUriExposedException:file:///storage/emulated/0/Pictures/MyPhotos 通过 Intent.getData() 暴露在应用程序之外
还有其他方法可以打开内部存储中的文件夹吗?谢谢!
更新#1
Uri myImagesdir = Uri.parse("file://" + path );
和
Uri myImagesdir = Uri.parse("content://" + path );
并且错误消失了。
无论如何,我必须选择总是应用程序来打开这个文件夹。
是否可以默认使用“我的文件”应用程序打开某些文件夹?