Home > Mobile >  Open specific folder with intent on Android Java
Open specific folder with intent on Android Java

Time:10-15

I want to open a specific folder with Intent but it only opens the recent files like this:

Recent Files

My code (updated):

 //path i want to open: /storage/emulated/0/Android/data/org.pytorch.demo.objectdetection/files/Pictures/saved_images

    String myDir = Environment.getExternalStorageDirectory()   "/"   "Android/data/org.pytorch.demo.objectdetection/files/Pictures/saved_images"   "/";
    Uri uri = Uri.parse(myDir);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, "*/*");
    startActivity(intent);

CodePudding user response:

try this, hope helpful for you

 String myDir = Environment.getExternalStorageDirectory()   "/"   "saved_images"   "/";
                Uri uri = Uri.parse(path);
                Intent intent = new Intent(Intent.ACTION_PICK);
                intent.setDataAndType(uri, "*/*");
                startActivity(intent);
            }

when the popup comes then select file manager or files

the complete solution is here : open a specific folder in andorid

for android 7.0 and grater versions use

add-in manifest

<application>

 <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>
</application>

create XML directory in resources (res)

files_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="my_images"
        path="Android/data/com.kslr.yours/files/Pictures" />

    <external-cache-path
        name="external-cache-path"
        path="."/>
    <external-files-path
        name="external-files-path"
        path="."/>
    <files-path
        name="files_path"
        path="."/>
    <cache-path
        name="cache-path"
        path="."/>

</paths>

CodePudding user response:

On an Android 11 device ACTION_VIEW can be used to let the Files or Documents app open in a specified directory.

Code has been published before.

One can only browse. Not pick a folder or file.

  • Related