I searched a lot and found the content type vnd.android.document/directory
.
Also, this includes other solutions for target API 24 and above. It showed the two apps to open it: OpenIntent File Manager and the built in File Manager.
This is research. And not a complete answer. If you find out what the arguments of the built-in file manager should be, let us know here.
File saveLocations
i.e. points to the DCIM folder.
// open a location with the file exporer
// see https://stackoverflow.com/a/26651827/1320237
// see https://stackoverflow.com/a/38858040
// see https://stackoverflow.com/a/8727354
Uri saveLocationUri = FileProvider.getUriForFile(this, this.getPackageName() + ".provider", saveLocation);
final Intent openSaveLocationIntent = new Intent(Intent.ACTION_VIEW);
openSaveLocationIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
openSaveLocationIntent.setDataAndType(saveLocationUri, "vnd.android.document/directory");
// see http://www.openintents.org/action/android-intent-action-view/file-directory
openSaveLocationIntent.putExtra("org.openintents.extra.ABSOLUTE_PATH", saveLocation.toString());
if (openSaveLocationIntent.resolveActivityInfo(getPackageManager(), 0) != null) {
startActivity(openSaveLocationIntent);
} else {
// if you reach this place, it means there is no any file
// explorer app installed on your device
}
It seems, there is a possiblity in Android 24+.
There is an intent filter to open directories:
<activity
android:name=".files.FilesActivity"
android:documentLaunchMode="intoExisting"
android:theme="@style/DocumentsTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.document/root" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.document/directory" />
</intent-filter>
</activity>
There is more code to it here:
https://github.com/derp-caf/packages_apps_DocumentsUI/blob/ab8e8638c87cd5f7fe1005800520e739b3a48cd5/src/com/android/documentsui/ScopedAccessActivity.java#L114
I am not sure how and the arguments can be set correctly.
// Sets args that will be retrieve on onCreate()
final Bundle args = new Bundle();
args.putString(EXTRA_FILE, file.getAbsolutePath());
args.putString(EXTRA_VOLUME_LABEL, volumeLabel);
args.putString(EXTRA_VOLUME_UUID, isPrimary ? null : storageVolume.getUuid());
args.putString(EXTRA_APP_LABEL, appLabel);
args.putBoolean(EXTRA_IS_ROOT, isRoot);
args.putBoolean(EXTRA_IS_PRIMARY, isPrimary);
I tried to put in some extra information but it still opens the activity in the root folder.
// from https://github.com/derp-caf/packages_apps_DocumentsUI/blob/ab8e8638c87cd5f7fe1005800520e739b3a48cd5/src/com/android/documentsui/ScopedAccessActivity.java#L114
openSaveLocationIntent.putExtra("com.android.documentsui.FILE", saveLocation.toString());
openSaveLocationIntent.putExtra("com.android.documentsui.IS_ROOT", false); // is the root folder?
openSaveLocationIntent.putExtra("com.android.documentsui.IS_PRIMARY", true); // is the primary volume? SD-Card should be false
openSaveLocationIntent.putExtra("com.android.documentsui.APP_LABEL", getTitle());