7

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.

Phantom
  • 968
  • 3
  • 14
  • 32

2 Answers2

8

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"));
shkschneider
  • 17,833
  • 13
  • 59
  • 112
  • But how can I start from a specific filePath ? – Phantom Apr 30 '15 at 12:54
  • Thank you for the reply but it doesn't redirect to that specific path, it open the default File manager location. Also, I would have want it to open the File Manager Application, not a popup from inside the app. – Phantom Apr 30 '15 at 13:15
  • Then I'm sorry to report that there is no standard/generic way of doing this. File Managers on Android all have their intents specifications and that's a mess I know. But you can't AFAIK. – shkschneider Apr 30 '15 at 13:17
4

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    
}
Slion
  • 2,558
  • 2
  • 23
  • 27