Issue in ACTION_OPEN_DOCUMENT_TREE

huangapple go评论132阅读模式
英文:

Issue in ACTION_OPEN_DOCUMENT_TREE

问题

我正在使用Android 11中的ACTION_OPEN_DOCUMENT_TREE方法来检测我的应用程序的SD卡内容。但是Android开发者网站关于这个方法提到了一个问题,即:

访问限制:
在Android 11(API级别30)及更高版本中,您不能使用ACTION_OPEN_DOCUMENT_TREE意图操作来请求对以下目录的访问权限:

  • 内部存储卷的根目录。
  • 设备制造商认为可靠的每个SD卡卷的根目录,无论该卡是否是模拟的或可移动的。
    • 可靠卷是应用程序大部分时间可以成功访问的卷。

所以我对是否使用ACTION OPEN DOCUMENT TREE方法感到困惑。请给我一些合适的解决方案。

英文:

I am Detecting the SD card content for my app using ACTION_OPEN_DOCUMENT_TREE method in Android version 11. But the Android developer website adds one issue about this method, which is:

Access restrictions:
On Android 11 (API level 30) and higher, you cannot use the ACTION_OPEN_DOCUMENT_TREE intent action to request access to the following directories:

  • The root directory of the internal storage volume.
  • The root directory of each SD card volume that the device manufacturer considers to be reliable, regardless of whether the card is emulated or removable.
    • A reliable volume is one that an app can successfully access most of the time.

So I am confused about whether I use ACTION OPEN DOCUMENT TREE Method or not. Please give me some proper solution.

答案1

得分: 0

you only can't access to the root directory
你只不能访问根目录

you can apply access to all sub directories.
你可以访问所有子目录。

I suggest you to see this GitHub sample project that gets access to WhatsApp status directory although it's created by another app:
我建议你查看这个GitHub示例项目,它可以访问WhatsApp状态目录,尽管它是由另一个应用程序创建的:
https://github.com/GauthamAsir/WhatsApp_Status_Saver/blob/master/app/src/main/java/a/gautham/statusdownloader/SplashActivity.java

you can create your own directory with ACTION_OPEN_DOCUMENT_TREE intent and get access to it.
你可以使用ACTION_OPEN_DOCUMENT_TREE意图创建自己的目录并访问它。

All of these concepts are about user privacy.
所有这些概念都涉及用户隐私。

These articles have been written by Google and can give you an idea:
这些文章是由Google撰写的,可以给你一些思路:
android 11 storage changes

https://developer.android.com/training/data-storage/app-specific

英文:

you only can't access to the root directory
you can apply access to all sub directories.
I suggest you to see this GitHub sample project that gets access to WhatsApp status directory although it's created by another app:
https://github.com/GauthamAsir/WhatsApp_Status_Saver/blob/master/app/src/main/java/a/gautham/statusdownloader/SplashActivity.java

you can create your own directory with ACTION_OPEN_DOCUMENT_TREE intent and get access to it.

    fun openDirectory(pickerInitialUri: Uri) {
    // Choose a directory using the system's file picker.
    val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
        // Optionally, specify a URI for the directory that should be opened in
        // the system file picker when it loads.
        putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)
    }
startActivityForResult(intent, 1001)
}

All of these concepts is about user privacy
these articles have written by Google can give you idea :
android 11 storage changes

https://developer.android.com/training/data-storage/app-specific

huangapple
  • 本文由 发表于 2023年6月4日 23:42:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401193.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定