如何只显示本地存储来选择Android中的文件



注意:所有类型的文件

我使用默认的Gallery Intent显示到存储,但它显示了Goggle驱动器选项和本地存储我尝试了以下参考资料,但没有什么对我有效。

参考:

  1. 如何让用户在Android中使用Intent只选择本地文件?2.https://stackoverflow.com/questions/27762377/android-why-intent-extra-local-only-shows-google-photos
  2. 在android中使用Intent.ACTION_GET_CONTENT时,是否可以隐藏谷歌驱动器

使用另一个库,以显示唯一的本地存储,它运行良好但要求是,需要仅显示本地存储及其所有文件类型以及文件大小,而此库中不可用。请建议一些其他库,如下面显示的文件大小

参考编号:https://github.com/codekidX/storage-chooserhttps://androidexample365.com/lets-user-choose-files-in-internal-or-external-storage-with-just-few-lines-of-code/

使用以下代码可以帮助您实现所需的结果:

val selectedUri =
Uri.parse(Environment.getExternalStorageDirectory().toString() + "/Pictures")
val intent = Intent(Intent.ACTION_PICK)
intent.data = selectedUri
intent.type = "image/*"
if (intent.resolveActivityInfo(context!!.packageManager, 0) != null) {
startActivityForResult(
intent,
101
)
} else {
// if you reach this place, it means there is no any file
// explorer app installed on your device
}

最新更新