从安卓应用中打开文件管理器

问题描述 投票:6回答:2

我怎样才能将我的应用程序重定向到一个特定的路径上打开文件管理器?

我已经尝试了类似的东西。

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

但我一直收到错误信息:

EAndroidRuntime(3591): android.content.ActivityNotFoundException: 没有找到处理Intent的Activity { act=android.intent.action.SEND typ=活动。 flg=0x1 pkg=my.package (has clip) (has extras) }。

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

谢谢你。

android android-intent file-manager
2个回答
6
投票

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

0
投票

其实这几天更像。

// 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    
}
© www.soinside.com 2019 - 2024. All rights reserved.