Android:打开文件夹对话框
问题描述:
我有下面的代码在Android中打开一个文件夹,虽然我看到很多帖子提到它的作品,我无法得到它的工作。Android:打开文件夹对话框
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
File f = new File(Environment.getExternalStorageDirectory(),"myFolder");
Uri uri = Uri.fromFile(f);
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
它只是打开根文件夹(在这种情况下,/ storage/sdcard而不是/ storage/sdcard/myfolder)。
任何人都知道为什么?
感谢
答
ACTION_GET_CONTENT
不documented使用一个Intent
的Uri
部分。虽然可能有一些应用程序的活动支持ACTION_GET_CONTENT
,但许多应用程序不会。
此外,Android并不真正适用于“文件夹”,因此在设备上不一定会有任何应用程序,它可以让您浏览任意东西。
欢迎您在Android 4.4+上使用the Storage Access Framework,这是Google处理用户浏览多个来源内容的中央系统UI的方法。或者file and directory picker libraries for Android。