本文介绍了为什么它没有通过Android中的意图打开已定义的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码将重定向到具有打开的导航功能的驱动器,但未打开实际的给定路径
旧代码
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/foldername/");
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setDataAndType(uri, "text/csv");
startActivity(intent);
我通过uri获取的路径值为:
/storage/emulated/0/myfolder
The path value I am getting through uri is:
/storage/emulated/0/myfolder
新代码
Intent resultIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
resultIntent.addCategory(Intent.CATEGORY_OPENABLE);
Uri uri =
Uri.parse(Environment.getExternalStorageDirectory().getPath() +
"/myfolder/");
resultIntent.setType("*/*");
resultIntent.putExtra("android.provider.extra.INITIAL_URI", uri);
// show the entire internal storage tree
//resultIntent.putExtra("android.content.extra.SHOW_ADVANCED", true);
startActivity(resultIntent);
让我知道问题所在,此代码中的问题所在.
Let me know the issue where is the problem in this code.
推荐答案
private static final int READ_REQUEST_CODE = 10;
...
/**
* Fires an intent to spin up the "file chooser" UI and select an image.
*/
public void performFileSearch() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(uri, "text/*");
startActivityForResult(intent, READ_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent resultData) {
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri uri = null;
if (resultData != null) {
uri = resultData.getData();
Log.i(TAG, "Uri: " + uri.toString());
showImage(uri);
}
}
}
这篇关于为什么它没有通过Android中的意图打开已定义的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!