首页 > 解决方案 > 如何在android中打开在应用程序中创建的文件夹

问题描述

我生成了一个文件夹名称“tesApplication”并在其中创建了一个文件名“testFile.csc”并将一些日期存储到该文件中。现在我想使用新意图打开文件夹目录。我尝试了下面的代码,但在我的情况下没有任何其他方式来实现这一点。

Uri selectedUri = Uri.parse(fileNameString);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(selectedUri, "text/csv");

    if (intent.resolveActivityInfo(getPackageManager(), 0) != null)
    {
        startActivity(intent);
    }
    else
    {
        // if you reach this place, it means there is no any file
        // explorer app installed on your device
    }

标签: androidfiledirectory

解决方案


把这个复制到其他地方

public void openFolder()
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
    + "/myFolder/");
intent.setDataAndType(uri, "text/csv");
startActivity(Intent.createChooser(intent, "Open folder"));
}

推荐阅读