rokkonet

PC・Androidソフトウェア・アプリの開発・使い方に関するメモ

android開発 ストレージ内のファイルの種別(URIのauthorityの種別)

2022 Apr. 29.
2022 Apr. 09.

出典
Android: Files: Unable to get file path from content URI when file is selected from RECENT section in file browser - Stack Overflow
android - cursor didn't have _data column not found - Stack Overflow
Androidで 静止画と動画のピッカーで選択したコンテンツのファイルパスを取得する - 酢ろぐ!

各種サイトの情報からすると、URIのauthorityに4つの種別がある?

"com.android.externalstorage.documents"
"com.android.providers.downloads.documents"
"com.android.providers.media.documents"
"com.google.android.apps.photos.content"

fun isExternalStorageDocument(uri: Uri): Boolean {
        return "com.android.externalstorage.documents" == uri.authority
}

fun isDownloadsDocument(uri: Uri): Boolean {
        return "com.android.providers.downloads.documents" == uri.authority
}

fun isMediaDocument(uri: Uri): Boolean {
        return "com.android.providers.media.documents" == uri.authority
}

fun isGooglePhotosUri(uri: Uri): Boolean {
        return "com.google.android.apps.photos.content" == uri.authority
}