简体   繁体   中英

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 .

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.

How will it open my defined URI folder directly? 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)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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