【问题标题】:Open the File Manager from an android app从安卓应用打开文件管理器
【发布时间】:2015-07-10 04:25:20
【问题描述】:

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

我尝试过类似的方法:

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: 找不到处理 Intent 的 Activity { act=android.intent.action.SEND typ=/ flg=0x1 pkg=my.package (有剪辑)(有额外内容)}

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

谢谢。

【问题讨论】:

    标签: android android-intent file-manager


    【解决方案1】:

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

    【讨论】:

    • 但是如何从特定的 filePath 开始?
    • 感谢您的回复,但它不会重定向到该特定路径,它会打开默认的文件管理器位置。另外,我希望它打开文件管理器应用程序,而不是应用程序内部的弹出窗口。
    • 那么我很遗憾地报告说没有标准/通用的方法来做到这一点。 Android 上的文件管理器都有自己的意图规范,我知道这是一团糟。但你不能 AFAIK。
    【解决方案2】:

    其实这几天更像是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多