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

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

在我的应用程序中我有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个回答
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"));
  }
© www.soinside.com 2019 - 2024. All rights reserved.