从 android 应用打开文件管理器

Open the File Manager from an android app

如何重定向我的应用程序以在特定路径打开文件管理器?

我尝试过类似的方法:

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);

但我一直收到错误消息:

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) }

什么是正确的 Intent 过滤器,我怀疑 ACTION_SEND 不正确。

谢谢。

您可以使用 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"));

实际上这几天更像是:

// 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    
}