如何以编程方式在android中打开目录

ali*_*ani 5 android android-intent

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

File file=new File(path);
        Uri url = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(url);
        startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

例外:

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 }
Run Code Online (Sandbox Code Playgroud)

我能做什么?

Roh*_*hit 0

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"));
  }
Run Code Online (Sandbox Code Playgroud)

  • setDataAndType 需要类型吗? (4认同)