I need to open folder in internal storage that contains images.
I use following code.
Java
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
<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>
Manifest
<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/file_paths
<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>
ERROR
FATAL EXCEPTION: main Process: android.apps.bnb.company.myphotos, PID: 22482 android.os.FileUriExposedException: file:///storage/emulated/0/Pictures/MyPhotos exposed beyond app through Intent.getData()
Is any another way to open folder in internal storage? Thanks!
UPDATE #1
Using this arcticle https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en I replaced
Uri myImagesdir = Uri.parse("file://" + path );
with
Uri myImagesdir = Uri.parse("content://" + path );
And the error gone.
Anyway I have to choose always app to open this folder.
Is it possibility to use My Files app by default to open certain folder?
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
line? – Dunajintent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
– DunajIs it possibility to use My Files app by default to open certain folder?
What do you want to achieve? can you elaborate? – SteepenIntent
structure for this, sorry. – Petrapetracca