简体   繁体   English

使用Click在Android中打开特定文件夹

[英]Open Specific Folder in Android with Click

I'm using the code below to open a folder created by my application but it's not working, though I got it from Trying open a specific folder in android using intent . 我正在使用下面的代码打开由我的应用程序创建的文件夹,但它不起作用,虽然我是从Trying使用intent打开一个特定的文件夹

public void openFolder() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String pa = sharedPreferences.getString("path", "");
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.parse(pa);
    intent.setDataAndType(uri, "*/*");
    startActivity(Intent.createChooser(intent, "Open folder"));
}

When I am sing Action_View, it shows all possible means except FileManager and in ACTION_GET_CONTENT it took me to SAF mode like to choose storage and then specific folders. 当我唱出Action_View时,它会显示除FileManager之外的所有可能方法,而在ACTION_GET_CONTENTACTION_GET_CONTENT我进入SAF模式,就像选择存储然后选择特定文件夹一样。

How will it open my defined URI folder directly? 它将如何直接打开我定义的URI文件夹? Is there any other way? 还有其他方法吗?

This should work... 这应该工作......

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String file= sharedPreferences.getString("path", "");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(Environment.getExternalStorageDirectory().getPath() + file), "*/*");
startActivity(Intent.createChooser(intent, getString(R.string.open_folder)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM