【问题标题】:How open directory in android programmatically如何以编程方式在android中打开目录
【发布时间】:2015-03-08 17:48:41
【问题描述】:

在我的应用程序中,我有在 ListActivity 中显示的文件列表,现在我想添加额外的选项,例如 windows :(打开文件夹位置) 以打开此文件的目录我测试一些代码但不工作抛出异常:

File file=new File(path);
        Uri url = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(url);
        startActivity(intent);

例外:

03-08 21:14:55.451: E/AndroidRuntime(15708): 
android.content.ActivityNotFoundException: No Activity found to handle Intent { 
act=android.intent.action.VIEW dat=file:///storage/extSdCard/Bluetooth }

我能做什么?

【问题讨论】:

    标签: android android-intent


    【解决方案1】:
    public void openFolder()
    {
       Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
       Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
    + "/Bluetooth /");
       intent.setDataAndType(uri);
       startActivity(Intent.createChooser(intent, "Open folder"));
      }
    

    【讨论】:

    • 这不适用于所有 android 文件管理器应用程序!
    • setDataAndType 需要类型吗?
    • @kyle 选择的应用程序可以从应用程序本身打开文件吗?不意味着应该怎么做才能从所选应用程序本身打开文件?
    猜你喜欢
    • 2015-04-23
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多