【问题标题】:How to show only local storage to Select the file in Android?如何仅显示本地存储以在 Android 中选择文件?
【发布时间】:2021-10-10 05:04:36
【问题描述】:

注意:所有类型的文件

我使用默认的 Gallery Intent 来显示存储,但它显示了 Goggle Drive 选项以及本地存储 我尝试了以下推荐,但对我没有任何作用。

参考:

  1. How to let user select only local files using Intent in Android? 2 .https://stackoverflow.com/questions/27762377/android-why-intent-extra-local-only-shows-google-photos
  2. Is it possible to hide google drive while using Intent.ACTION_GET_CONTENT in android?

使用另一个库,显示唯一的本地存储,它工作正常 但要求是,只需要显示本地存储及其所有文件类型以及文件大小,这在此库中不可用。 请建议其他一些类似下面显示文件大小的库

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

【问题讨论】:

  • default Gallery Intent ?没听说过。你认为那是什么?
  • 意图意图 = new Intent();意图.setType("/");意图.setAction(意图.ACTION_GET_CONTENT); intent.putExtra("android.content.extra.SHOW_ADVANCED", true); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); startActivityForResult(Intent.createChooser(intent, "选择文件"), 10);我使用上面的代码作为默认意图

标签: android


【解决方案1】:

使用下面的代码可以帮助您达到预期的效果:

        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
        }

【讨论】:

  • Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory().toString()); Intent 意图 = new Intent(Intent.ACTION_PICK);意图.setData(selectedUri);意图.setType("/"); if (intent.resolveActivityInfo(mContext.getPackageManager(), 0) != null) { startActivityForResult(intent, 10); } else { } 像上面一样修改代码,如果我们提到了特定的文件夹名称,它返回相同的结果,它不显示存储的东西,只有谷歌照片选项是可见的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-03
  • 2018-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-20
  • 1970-01-01
相关资源
最近更新 更多