Free/total space of a USB flash drive can be accessed only with “Manage all files on a storage device” permission. Is this a joke?

First: there is no way Google will approve this permission for apps which aren’t

  • File managers
  • Backup and restore apps
  • Anti-virus apps
  • Document management apps
  • On-device file search
  • Disk and file encryption
  • Device-to-device data migration

based on their Google Play notice

So we are left with SAF, MediaStore… (very limited stuff)

I have an app which can record videos with loop recording option to automatically delete older videos when storage is almost full or when the max space for videos (set by users) is reached.

To record videos with MediaRecorder I can use SAF or MediaStore, so it’s not a problem, no need in android.permission.MANAGE_EXTERNAL_STORAGE (Manage all files on a storage device) permission.

So this app which records videos is not suitable for MANAGE_EXTERNAL_STORAGE permission based on Google policy.

But for loop recording feature I need to know free and total space of the storage, and the directory of videos selected by users (for the max space option).

Luckily I can still use StorageManager to get info about the storages of a device and it seems it doesn’t need any permissions!

Dialogue:

  • “Really? Is StorageManager that great and doesn’t need any permission to get info about space?”

  • “Yes, but only if it’s built-in internal storage or microSD card!!! Though with microSD cards there is no guarantee in some cases”

  • “What about a USB flash drive? I know that Android supports them from the box to read/write files”

  • “HAHA! YOU NEED MANAGE_EXTERNAL_STORAGE permission in this case, suffer!”

So my users asks about the possibility to record videos to a USB flash drive, for example they may use it with their car radio (head unit) Android devices or even just Android smartphones.

So I have connected a USB flash drive to my Samsung phone using USB OTG:

And I tried to get info about storages using StorageManager:

fun getStorageInfo(context: Context): List<String> {
    val storageManager =
        context.getSystemService(Context.STORAGE_SERVICE) as StorageManager
    val storages = storageManager.storageVolumes
        .mapIndexedNotNull { index, volume ->
            buildString {
                val file = getVolumeFileRoot(volume)
                appendLine("#${index + 1} Storage")
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                    appendLine("mediaStoreVolumeName: ${volume.mediaStoreVolumeName}")
                }
                appendLine("uuid: ${volume.uuid}")
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
                    appendLine("storageUuid: ${volume.storageUuid}")
                }
                appendLine("File.path: $file")
                appendLine("File.isDirectory: ${file?.isDirectory}")
                appendLine("desc: ${volume.getDescription(context)}")
                appendLine("state: ${volume.state}")
                appendLine("isRemovable: ${volume.isRemovable}")
                appendLine("isEmulated: ${volume.isEmulated}")
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
                    appendLine("isPrimary: ${volume.isPrimary}")
                    appendLine("allocatedBytes: ${
                        volume.storageUuid?.let {
                            storageManager.getAllocatableBytes(it)
                        }
                    }")
                }
                file?.let {
                    appendLine("File.canRead: ${it.canRead()}")
                    appendLine("File.canWrite: ${it.canWrite()}")
                    appendLine("File.freeSpace: ${it.freeSpace}")
                    appendLine("File.totalSpace: ${it.totalSpace}")
                    appendLine("File.usableSpace: ${it.usableSpace}")
                }
            }
        }
    return storages
}

As you can see I can get info about free/total space only for internal storage but not for a USB flash drive!

So I tried to add <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> to the manifest and grant the permission with:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ...
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
        && !Environment.isExternalStorageManager()
    ) {
        startActivity(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION))
    }
}

(which can’t be used for Google Play – won’t be approved by Evil Google)

Started the app and granted the all files permission and now I can access free/total space info of my USB flash drive.

But only me, with a debug app, and not my users!

But it can be even worse – some users reported that it happens (though rarely) with microSD cards as well on some car radio devices without this permission of course, so the info can’t be retrieved just like with USB flash drives. Only internal storage can be used normally. But also mb there were cases with phones and microSD cards as well.

Yeah, sorry, I know that I have 10k reputation on SO already, but come on, enough is enough, some things in Google Android are a joke, let’s admit it, it’s a total disaster.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật