简体   繁体   中英

ContentResolver.openAssetFileDescriptor() takes a long time in Android 12

In Android 12, this method call takes multiple seconds to return:

val descriptor = contentResolver.openAssetFileDescriptor(rootUri, "r")

I'm passing it a tree Uri which represents the root of a USB drive. The call takes longer depending on how much space is taken up on the root. So for 1GB, it takes about 10 seconds. This isn't the case in previous Android versions, where the call returns in just a few millis.

My goal is to measure the space on a USB drive using the code below. Is there something else I can do to make this complete in a reasonable amount of time?

val descriptor = contentResolver.openAssetFileDescriptor(rootUri, "r")
val stats = Os.fstatvfs(descriptor!!.fileDescriptor)
val availableSpace = stats.f_bavail * stats.f_bsize

Relevant link

Google Issue tracker link with sample project

For Android 12 you can request raw file acces. (Forgot the right name of the permission)

When you do all file operations pass by the mediastore.

Worth a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM