Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open the File Manager from an android app

How can I redirect my app to open the File manager at a specific path ?

I've tried something like:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("*/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM,
            Uri.fromFile(new File(filePath)));
    shareIntent.setPackage("my.package");
    startActivity(shareIntent);

But I keep get the error:

E/AndroidRuntime(3591): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=/ flg=0x1 pkg=my.package (has clip) (has extras) }

What is the correct intent filter, as I suspect ACTION_SEND is not the correct one.

Thank you.

like image 823
Phantom Avatar asked Apr 30 '15 12:04

Phantom


People also ask

How do I open file manager on Android?

To access this File Manager, open Android's Settings app from the app drawer. Tap “Storage & USB” under the Device category. This takes you to Android's storage manager, which helps you free up space on your Android device.

What is a file manager app on Android?

A file manager application can help you organize, store and transfer files on your mobile device. You can choose from several file manager apps for Android or iOS. File manager apps are great for freeing up storage on your mobile device and securely storing important files.


2 Answers

You can use Intent.ACTION_GET_CONTENT:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse("/whatever/path/you/want/"); // a directory
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
like image 58
shkschneider Avatar answered Sep 18 '22 03:09

shkschneider


Actually this days it's more like:

// Construct an intent for opening a folder
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(aDownloadFolder), "resource/folder");
// Check that there is an app activity handling that intent on our system
if (intent.resolveActivityInfo(aContext.getPackageManager(), 0) != null) {
    // Yes there is one start it then
    startActivity(intent);
} else {
    // Did not find any activity capable of handling that intent on our system 
    // TODO: Display error message or something    
}
like image 27
Slion Avatar answered Sep 22 '22 03:09

Slion