-
public class DocumentFileCompatCreated on 16/08/20
-
-
Field Summary
Fields Modifier and Type Field Description private final StringEXTERNAL_STORAGE_AUTHORITYprivate final StringDOWNLOADS_FOLDER_AUTHORITYprivate final StringMEDIA_FOLDER_AUTHORITYprivate final StringDOWNLOADS_TREE_URIprivate final StringDOCUMENTS_TREE_URIprivate final RegexFILE_NAME_DUPLICATION_REGEX_WITH_EXTENSIONprivate final RegexFILE_NAME_DUPLICATION_REGEX_WITHOUT_EXTENSIONprivate final RegexSD_CARD_STORAGE_ID_REGEXprivate final RegexSD_CARD_STORAGE_PATH_REGEXpublic final static DocumentFileCompatINSTANCE
-
Method Summary
Modifier and Type Method Description final FilegetKitkatSdCardRootFile(String basePath)final static BooleanisRootUri(Uri uri)final static StringgetStorageId(Context context, String fullPath)final static StringgetBasePath(Context context, String fullPath)final static DocumentFilefromUri(Context context, Uri uri)final static DocumentFilefromSimplePath(Context context, String storageId, String basePath, DocumentFileType documentType, Boolean requiresWriteAccess, Boolean considerRawFile)final static DocumentFilefromSimplePath(Context context, String storageId, String basePath, DocumentFileType documentType, Boolean requiresWriteAccess)final static DocumentFilefromSimplePath(Context context, String storageId, String basePath, DocumentFileType documentType)final static DocumentFilefromSimplePath(Context context, String storageId, String basePath)final static DocumentFilefromSimplePath(Context context, String storageId)final static DocumentFilefromSimplePath(Context context)final static DocumentFilefromFullPath(Context context, String fullPath, DocumentFileType documentType, Boolean requiresWriteAccess, Boolean considerRawFile)fileFullPathfor example:For file in external storage =>
/storage/emulated/0/Downloads/MyMovie.mp4.For file in SD card =>
/storage/9016-4EF8/Downloads/MyMovie.mp4or you can input simple path like this9016-4EF8:Downloads/MyMovie.mp4. You can input9016-4EF8:or/storage/9016-4EF8for SD card's root path.
final static DocumentFilefromFullPath(Context context, String fullPath, DocumentFileType documentType, Boolean requiresWriteAccess)fileFullPathfor example:For file in external storage =>
/storage/emulated/0/Downloads/MyMovie.mp4.For file in SD card =>
/storage/9016-4EF8/Downloads/MyMovie.mp4or you can input simple path like this9016-4EF8:Downloads/MyMovie.mp4. You can input9016-4EF8:or/storage/9016-4EF8for SD card's root path.
final static DocumentFilefromFullPath(Context context, String fullPath, DocumentFileType documentType)fileFullPathfor example:For file in external storage =>
/storage/emulated/0/Downloads/MyMovie.mp4.For file in SD card =>
/storage/9016-4EF8/Downloads/MyMovie.mp4or you can input simple path like this9016-4EF8:Downloads/MyMovie.mp4. You can input9016-4EF8:or/storage/9016-4EF8for SD card's root path.
final static DocumentFilefromFullPath(Context context, String fullPath)fileFullPathfor example:For file in external storage =>
/storage/emulated/0/Downloads/MyMovie.mp4.For file in SD card =>
/storage/9016-4EF8/Downloads/MyMovie.mp4or you can input simple path like this9016-4EF8:Downloads/MyMovie.mp4. You can input9016-4EF8:or/storage/9016-4EF8for SD card's root path.
final static DocumentFilefromFile(Context context, File file, DocumentFileType documentType, Boolean requiresWriteAccess, Boolean considerRawFile)Since Android 10, only app directory that is accessible by File, e.g. final static DocumentFilefromFile(Context context, File file, DocumentFileType documentType, Boolean requiresWriteAccess)Since Android 10, only app directory that is accessible by File, e.g. final static DocumentFilefromFile(Context context, File file, DocumentFileType documentType)Since Android 10, only app directory that is accessible by File, e.g. final static DocumentFilefromFile(Context context, File file)Since Android 10, only app directory that is accessible by File, e.g. final static DocumentFilefromPublicFolder(Context context, PublicDirectory type, String subFile, Boolean requiresWriteAccess, Boolean considerRawFile)Returns nullif folder does not exist or you have no permission on this directoryfinal static DocumentFilefromPublicFolder(Context context, PublicDirectory type, String subFile, Boolean requiresWriteAccess)Returns nullif folder does not exist or you have no permission on this directoryfinal static DocumentFilefromPublicFolder(Context context, PublicDirectory type, String subFile)Returns nullif folder does not exist or you have no permission on this directoryfinal static DocumentFilefromPublicFolder(Context context, PublicDirectory type)Returns nullif folder does not exist or you have no permission on this directoryfinal static DocumentFilegetRootDocumentFile(Context context, String storageId, Boolean requiresWriteAccess, Boolean considerRawFile)To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime. final static DocumentFilegetRootDocumentFile(Context context, String storageId, Boolean requiresWriteAccess)To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime. final static DocumentFilegetRootDocumentFile(Context context, String storageId)To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime. final static DocumentFilegetAccessibleRootDocumentFile(Context context, String fullPath, Boolean requiresWriteAccess, Boolean considerRawFile)In API 29+, /storage/emulated/0may not be granted for URI permission, but all directories under/storage/emulated/0/Musicare granted and accessible.final static DocumentFilegetAccessibleRootDocumentFile(Context context, String fullPath, Boolean requiresWriteAccess)In API 29+, /storage/emulated/0may not be granted for URI permission, but all directories under/storage/emulated/0/Musicare granted and accessible.final static DocumentFilegetAccessibleRootDocumentFile(Context context, String fullPath)In API 29+, /storage/emulated/0may not be granted for URI permission, but all directories under/storage/emulated/0/Musicare granted and accessible.final static FilegetRootRawFile(Context context, String storageId, Boolean requiresWriteAccess)To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime. final static FilegetRootRawFile(Context context, String storageId)To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime. final static StringbuildAbsolutePath(Context context, String storageId, String basePath)final static StringbuildAbsolutePath(Context context, String simplePath)final static StringbuildSimplePath(String storageId, String basePath)final static StringbuildSimplePath(Context context, String absolutePath)final static UricreateDocumentUri(String storageId, String basePath)final static UricreateDocumentUri(String storageId)final static BooleanisAccessGranted(Context context, String storageId)final static BooleandoesExist(Context context, String fullPath)final static Booleandelete(Context context, String fullPath)final static <ERROR CLASS>isStorageUriPermissionGranted(Context context, String storageId, String basePath)Check if storage has URI permission for read and write access. final static <ERROR CLASS>isStorageUriPermissionGranted(Context context, String storageId)Check if storage has URI permission for read and write access. final static <ERROR CLASS>isDownloadsUriPermissionGranted(Context context)final static <ERROR CLASS>isDocumentsUriPermissionGranted(Context context)final static List<String>getStorageIds(Context context)Get all storage IDs on this device. final static <ERROR CLASS>getSdCardIds(Context context)final static Map<String, Set<String>>getAccessibleAbsolutePaths(Context context)The key of the map is storage ID, and the values are granted absolute paths. final static Map<String, List<Uri>>getAccessibleUris(Context context)final static DocumentFilemkdirs(Context context, String fullPath, Boolean requiresWriteAccess, Boolean considerRawFile)Create folders. final static DocumentFilemkdirs(Context context, String fullPath, Boolean requiresWriteAccess)Create folders. final static DocumentFilemkdirs(Context context, String fullPath)Create folders. final static Array<DocumentFile>mkdirs(Context context, List<String> fullPaths, Boolean requiresWriteAccess, Boolean considerRawFile)Optimized performance for creating multiple folders. final static Array<DocumentFile>mkdirs(Context context, List<String> fullPaths, Boolean requiresWriteAccess)Optimized performance for creating multiple folders. final static Array<DocumentFile>mkdirs(Context context, List<String> fullPaths)Optimized performance for creating multiple folders. final static FileWrappercreateDownloadWithMediaStoreFallback(Context context, FileDescription file)final static FileWrappercreatePictureWithMediaStoreFallback(Context context, FileDescription file)final static DocumentFilecreateFile(Context context, String storageId, String basePath, String mimeType, Boolean considerRawFile)final static DocumentFilecreateFile(Context context, String storageId, String basePath, String mimeType)final static DocumentFilecreateFile(Context context, String storageId, String basePath)final static DocumentFilecreateFile(Context context, String basePath)final static DocumentFilerecreate(Context context, String storageId, String basePath, String mimeType, Boolean considerRawFile)final static DocumentFilerecreate(Context context, String storageId, String basePath, String mimeType)final static DocumentFilerecreate(Context context, String storageId, String basePath)final static DocumentFilerecreate(Context context, String basePath)final static List<String>findUniqueDeepestSubFolders(Context context, Collection<String> folderFullPaths)Given the following folderFullPaths:/storage/9016-4EF8/Downloads/storage/9016-4EF8/Downloads/Archive/storage/9016-4EF8/Video/storage/9016-4EF8/Music/storage/9016-4EF8/Music/Favorites/Pop/storage/emulated/0/Musicprimary:Alarm/Morningprimary:Alarm
/storage/9016-4EF8/Downloads/Archive/storage/9016-4EF8/Music/Favorites/Pop/storage/9016-4EF8/Video/storage/emulated/0/Music/storage/emulated/0/Alarm/Morning
final static List<String>findUniqueParents(Context context, Collection<String> folderFullPaths)Given the following folderFullPaths:/storage/9016-4EF8/Downloads/storage/9016-4EF8/Downloads/Archive/storage/9016-4EF8/Video/storage/9016-4EF8/Music/storage/9016-4EF8/Music/Favorites/Pop/storage/emulated/0/Musicprimary:Alarm/Morningprimary:Alarm
/storage/9016-4EF8/Downloads/storage/9016-4EF8/Music/storage/9016-4EF8/Video/storage/emulated/0/Music/storage/emulated/0/Alarm
final static List<String>findInaccessibleStorageLocations(Context context, List<String> fullPaths)final static LonggetFreeSpace(Context context, String storageId)final static LonggetUsedSpace(Context context, String storageId)final static LonggetStorageCapacity(Context context, String storageId)final static StringgetFileNameFromUrl(String url)final StringgetEXTERNAL_STORAGE_AUTHORITY()final StringgetDOWNLOADS_FOLDER_AUTHORITY()final StringgetMEDIA_FOLDER_AUTHORITY()final StringgetDOWNLOADS_TREE_URI()Only available on API 26 to 29. final StringgetDOCUMENTS_TREE_URI()Only available on API 24 to 29. final RegexgetFILE_NAME_DUPLICATION_REGEX_WITH_EXTENSION()final RegexgetFILE_NAME_DUPLICATION_REGEX_WITHOUT_EXTENSION()final RegexgetSD_CARD_STORAGE_ID_REGEX()final RegexgetSD_CARD_STORAGE_PATH_REGEX()-
-
Method Detail
-
getKitkatSdCardRootFile
@RestrictTo(value = {RestrictTo.Scope.LIBRARY}) final File getKitkatSdCardRootFile(String basePath)
-
getStorageId
final static String getStorageId(Context context, String fullPath)
- Parameters:
fullPath- For SD card can be full pathstorage/6881-2249/Musicor simple path6881-2249:Music.
-
getBasePath
final static String getBasePath(Context context, String fullPath)
- Parameters:
fullPath- For SD card can be full pathstorage/6881-2249/Musicor simple path6881-2249:Music.
-
fromUri
final static DocumentFile fromUri(Context context, Uri uri)
-
fromSimplePath
@JvmOverloads() final static DocumentFile fromSimplePath(Context context, String storageId, String basePath, DocumentFileType documentType, Boolean requiresWriteAccess, Boolean considerRawFile)
- Parameters:
storageId- If in SD card, it should be integers like6881-2249.basePath- If in Downloads folder of SD card, it will beDownloads/MyMovie.mp4.
-
fromSimplePath
@JvmOverloads() final static DocumentFile fromSimplePath(Context context, String storageId, String basePath, DocumentFileType documentType, Boolean requiresWriteAccess)
- Parameters:
storageId- If in SD card, it should be integers like6881-2249.basePath- If in Downloads folder of SD card, it will beDownloads/MyMovie.mp4.
-
fromSimplePath
@JvmOverloads() final static DocumentFile fromSimplePath(Context context, String storageId, String basePath, DocumentFileType documentType)
- Parameters:
storageId- If in SD card, it should be integers like6881-2249.basePath- If in Downloads folder of SD card, it will beDownloads/MyMovie.mp4.
-
fromSimplePath
@JvmOverloads() final static DocumentFile fromSimplePath(Context context, String storageId, String basePath)
- Parameters:
storageId- If in SD card, it should be integers like6881-2249.basePath- If in Downloads folder of SD card, it will beDownloads/MyMovie.mp4.
-
fromSimplePath
@JvmOverloads() final static DocumentFile fromSimplePath(Context context, String storageId)
- Parameters:
storageId- If in SD card, it should be integers like6881-2249.
-
fromSimplePath
@JvmOverloads() final static DocumentFile fromSimplePath(Context context)
-
fromFullPath
@JvmOverloads() final static DocumentFile fromFullPath(Context context, String fullPath, DocumentFileType documentType, Boolean requiresWriteAccess, Boolean considerRawFile)
fileFullPathfor example:For file in external storage =>
/storage/emulated/0/Downloads/MyMovie.mp4.For file in SD card =>
/storage/9016-4EF8/Downloads/MyMovie.mp4or you can input simple path like this9016-4EF8:Downloads/MyMovie.mp4. You can input9016-4EF8:or/storage/9016-4EF8for SD card's root path.
-
fromFullPath
@JvmOverloads() final static DocumentFile fromFullPath(Context context, String fullPath, DocumentFileType documentType, Boolean requiresWriteAccess)
fileFullPathfor example:For file in external storage =>
/storage/emulated/0/Downloads/MyMovie.mp4.For file in SD card =>
/storage/9016-4EF8/Downloads/MyMovie.mp4or you can input simple path like this9016-4EF8:Downloads/MyMovie.mp4. You can input9016-4EF8:or/storage/9016-4EF8for SD card's root path.
-
fromFullPath
@JvmOverloads() final static DocumentFile fromFullPath(Context context, String fullPath, DocumentFileType documentType)
fileFullPathfor example:For file in external storage =>
/storage/emulated/0/Downloads/MyMovie.mp4.For file in SD card =>
/storage/9016-4EF8/Downloads/MyMovie.mp4or you can input simple path like this9016-4EF8:Downloads/MyMovie.mp4. You can input9016-4EF8:or/storage/9016-4EF8for SD card's root path.
-
fromFullPath
@JvmOverloads() final static DocumentFile fromFullPath(Context context, String fullPath)
fileFullPathfor example:For file in external storage =>
/storage/emulated/0/Downloads/MyMovie.mp4.For file in SD card =>
/storage/9016-4EF8/Downloads/MyMovie.mp4or you can input simple path like this9016-4EF8:Downloads/MyMovie.mp4. You can input9016-4EF8:or/storage/9016-4EF8for SD card's root path.
-
fromFile
@JvmOverloads() final static DocumentFile fromFile(Context context, File file, DocumentFileType documentType, Boolean requiresWriteAccess, Boolean considerRawFile)
Since Android 10, only app directory that is accessible by File, e.g.
/storage/emulated/0/Android/data/com.anggrayudi.storage.sample/filesTo continue using File, you need to request full storage access via SimpleStorage.requestFullStorageAccess
This function allows you to read and write files in external storage, regardless of API levels.
- Parameters:
considerRawFile-trueif you want to consider faster performance with File
-
fromFile
@JvmOverloads() final static DocumentFile fromFile(Context context, File file, DocumentFileType documentType, Boolean requiresWriteAccess)
Since Android 10, only app directory that is accessible by File, e.g.
/storage/emulated/0/Android/data/com.anggrayudi.storage.sample/filesTo continue using File, you need to request full storage access via SimpleStorage.requestFullStorageAccess
This function allows you to read and write files in external storage, regardless of API levels.
-
fromFile
@JvmOverloads() final static DocumentFile fromFile(Context context, File file, DocumentFileType documentType)
Since Android 10, only app directory that is accessible by File, e.g.
/storage/emulated/0/Android/data/com.anggrayudi.storage.sample/filesTo continue using File, you need to request full storage access via SimpleStorage.requestFullStorageAccess
This function allows you to read and write files in external storage, regardless of API levels.
-
fromFile
@JvmOverloads() final static DocumentFile fromFile(Context context, File file)
Since Android 10, only app directory that is accessible by File, e.g.
/storage/emulated/0/Android/data/com.anggrayudi.storage.sample/filesTo continue using File, you need to request full storage access via SimpleStorage.requestFullStorageAccess
This function allows you to read and write files in external storage, regardless of API levels.
-
fromPublicFolder
@JvmOverloads() final static DocumentFile fromPublicFolder(Context context, PublicDirectory type, String subFile, Boolean requiresWriteAccess, Boolean considerRawFile)
Returns
nullif folder does not exist or you have no permission on this directory- Parameters:
subFile- can input sub folder or sub file
-
fromPublicFolder
@JvmOverloads() final static DocumentFile fromPublicFolder(Context context, PublicDirectory type, String subFile, Boolean requiresWriteAccess)
Returns
nullif folder does not exist or you have no permission on this directory- Parameters:
subFile- can input sub folder or sub file
-
fromPublicFolder
@JvmOverloads() final static DocumentFile fromPublicFolder(Context context, PublicDirectory type, String subFile)
Returns
nullif folder does not exist or you have no permission on this directory- Parameters:
subFile- can input sub folder or sub file
-
fromPublicFolder
@JvmOverloads() final static DocumentFile fromPublicFolder(Context context, PublicDirectory type)
Returns
nullif folder does not exist or you have no permission on this directory
-
getRootDocumentFile
@JvmOverloads() final static DocumentFile getRootDocumentFile(Context context, String storageId, Boolean requiresWriteAccess, Boolean considerRawFile)
To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime.
-
getRootDocumentFile
@JvmOverloads() final static DocumentFile getRootDocumentFile(Context context, String storageId, Boolean requiresWriteAccess)
To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime.
-
getRootDocumentFile
@JvmOverloads() final static DocumentFile getRootDocumentFile(Context context, String storageId)
To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime.
-
getAccessibleRootDocumentFile
@JvmOverloads() final static DocumentFile getAccessibleRootDocumentFile(Context context, String fullPath, Boolean requiresWriteAccess, Boolean considerRawFile)
In API 29+,
/storage/emulated/0may not be granted for URI permission, but all directories under/storage/emulated/0/Musicare granted and accessible.For example, given
/storage/emulated/0/Music/Metal, then return/storage/emulated/0/Music- Parameters:
fullPath- construct it using buildAbsolutePath or buildSimplePath
-
getAccessibleRootDocumentFile
@JvmOverloads() final static DocumentFile getAccessibleRootDocumentFile(Context context, String fullPath, Boolean requiresWriteAccess)
In API 29+,
/storage/emulated/0may not be granted for URI permission, but all directories under/storage/emulated/0/Musicare granted and accessible.For example, given
/storage/emulated/0/Music/Metal, then return/storage/emulated/0/Music- Parameters:
fullPath- construct it using buildAbsolutePath or buildSimplePath
-
getAccessibleRootDocumentFile
@JvmOverloads() final static DocumentFile getAccessibleRootDocumentFile(Context context, String fullPath)
In API 29+,
/storage/emulated/0may not be granted for URI permission, but all directories under/storage/emulated/0/Musicare granted and accessible.For example, given
/storage/emulated/0/Music/Metal, then return/storage/emulated/0/Music- Parameters:
fullPath- construct it using buildAbsolutePath or buildSimplePath
-
getRootRawFile
@JvmOverloads() final static File getRootRawFile(Context context, String storageId, Boolean requiresWriteAccess)
To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime.
-
getRootRawFile
@JvmOverloads() final static File getRootRawFile(Context context, String storageId)
To get root file access on API 30+, you need to have full storage access by granting Manifest.permission.MANAGE_EXTERNAL_STORAGE in runtime.
-
buildAbsolutePath
final static String buildAbsolutePath(Context context, String storageId, String basePath)
-
buildAbsolutePath
final static String buildAbsolutePath(Context context, String simplePath)
-
buildSimplePath
final static String buildSimplePath(String storageId, String basePath)
-
buildSimplePath
final static String buildSimplePath(Context context, String absolutePath)
-
createDocumentUri
@JvmOverloads() final static Uri createDocumentUri(String storageId, String basePath)
-
createDocumentUri
@JvmOverloads() final static Uri createDocumentUri(String storageId)
-
isAccessGranted
final static Boolean isAccessGranted(Context context, String storageId)
-
isStorageUriPermissionGranted
@JvmOverloads() final static <ERROR CLASS> isStorageUriPermissionGranted(Context context, String storageId, String basePath)
Check if storage has URI permission for read and write access.
Persisted URIs revoked whenever the related folders deleted. Hence, you need to request URI permission again even though the folder recreated by user. However, you should not worry about this on API 28 and lower, because URI permission always granted for root path and root path itself can't be deleted.
-
isStorageUriPermissionGranted
@JvmOverloads() final static <ERROR CLASS> isStorageUriPermissionGranted(Context context, String storageId)
Check if storage has URI permission for read and write access.
Persisted URIs revoked whenever the related folders deleted. Hence, you need to request URI permission again even though the folder recreated by user. However, you should not worry about this on API 28 and lower, because URI permission always granted for root path and root path itself can't be deleted.
-
isDownloadsUriPermissionGranted
final static <ERROR CLASS> isDownloadsUriPermissionGranted(Context context)
-
isDocumentsUriPermissionGranted
final static <ERROR CLASS> isDocumentsUriPermissionGranted(Context context)
-
getStorageIds
final static List<String> getStorageIds(Context context)
Get all storage IDs on this device. The first index is primary storage. Prior to API 28, retrieving storage ID for SD card only applicable if URI permission is granted for read & write access.
-
getSdCardIds
final static <ERROR CLASS> getSdCardIds(Context context)
-
getAccessibleAbsolutePaths
final static Map<String, Set<String>> getAccessibleAbsolutePaths(Context context)
The key of the map is storage ID, and the values are granted absolute paths. Use it if you want to know what paths that are accessible by your app.
-
mkdirs
@JvmOverloads() final static DocumentFile mkdirs(Context context, String fullPath, Boolean requiresWriteAccess, Boolean considerRawFile)
Create folders. You should do this process in background.
- Parameters:
fullPath- construct it using buildAbsolutePath or buildSimplePathrequiresWriteAccess- the folder should have write access, otherwise returnnull
-
mkdirs
@JvmOverloads() final static DocumentFile mkdirs(Context context, String fullPath, Boolean requiresWriteAccess)
Create folders. You should do this process in background.
- Parameters:
fullPath- construct it using buildAbsolutePath or buildSimplePathrequiresWriteAccess- the folder should have write access, otherwise returnnull
-
mkdirs
@JvmOverloads() final static DocumentFile mkdirs(Context context, String fullPath)
Create folders. You should do this process in background.
- Parameters:
fullPath- construct it using buildAbsolutePath or buildSimplePath
-
mkdirs
@JvmOverloads() final static Array<DocumentFile> mkdirs(Context context, List<String> fullPaths, Boolean requiresWriteAccess, Boolean considerRawFile)
Optimized performance for creating multiple folders. The result may contains
nullelements for unsuccessful creation. For instance, if parameterfullPathscontains 5 elements and successfulmkdirs()is 3, then return 3 non-null elements + 2 null elements.- Parameters:
fullPaths- either simple path or absolute path.requiresWriteAccess- the folder should have write access, otherwise returnnull
-
mkdirs
@JvmOverloads() final static Array<DocumentFile> mkdirs(Context context, List<String> fullPaths, Boolean requiresWriteAccess)
Optimized performance for creating multiple folders. The result may contains
nullelements for unsuccessful creation. For instance, if parameterfullPathscontains 5 elements and successfulmkdirs()is 3, then return 3 non-null elements + 2 null elements.- Parameters:
fullPaths- either simple path or absolute path.requiresWriteAccess- the folder should have write access, otherwise returnnull
-
mkdirs
@JvmOverloads() final static Array<DocumentFile> mkdirs(Context context, List<String> fullPaths)
Optimized performance for creating multiple folders. The result may contains
nullelements for unsuccessful creation. For instance, if parameterfullPathscontains 5 elements and successfulmkdirs()is 3, then return 3 non-null elements + 2 null elements.- Parameters:
fullPaths- either simple path or absolute path.
-
createDownloadWithMediaStoreFallback
final static FileWrapper createDownloadWithMediaStoreFallback(Context context, FileDescription file)
-
createPictureWithMediaStoreFallback
final static FileWrapper createPictureWithMediaStoreFallback(Context context, FileDescription file)
-
createFile
@JvmOverloads() final static DocumentFile createFile(Context context, String storageId, String basePath, String mimeType, Boolean considerRawFile)
- Parameters:
basePath- file path without root path, e.g.
-
createFile
@JvmOverloads() final static DocumentFile createFile(Context context, String storageId, String basePath, String mimeType)
- Parameters:
basePath- file path without root path, e.g.
-
createFile
@JvmOverloads() final static DocumentFile createFile(Context context, String storageId, String basePath)
- Parameters:
basePath- file path without root path, e.g.
-
createFile
@JvmOverloads() final static DocumentFile createFile(Context context, String basePath)
- Parameters:
basePath- file path without root path, e.g.
-
recreate
@JvmOverloads() final static DocumentFile recreate(Context context, String storageId, String basePath, String mimeType, Boolean considerRawFile)
-
recreate
@JvmOverloads() final static DocumentFile recreate(Context context, String storageId, String basePath, String mimeType)
-
recreate
@JvmOverloads() final static DocumentFile recreate(Context context, String storageId, String basePath)
-
recreate
@JvmOverloads() final static DocumentFile recreate(Context context, String basePath)
-
findUniqueDeepestSubFolders
final static List<String> findUniqueDeepestSubFolders(Context context, Collection<String> folderFullPaths)
Given the following
folderFullPaths:/storage/9016-4EF8/Downloads/storage/9016-4EF8/Downloads/Archive/storage/9016-4EF8/Video/storage/9016-4EF8/Music/storage/9016-4EF8/Music/Favorites/Pop/storage/emulated/0/Musicprimary:Alarm/Morningprimary:Alarm
Then return:
/storage/9016-4EF8/Downloads/Archive/storage/9016-4EF8/Music/Favorites/Pop/storage/9016-4EF8/Video/storage/emulated/0/Music/storage/emulated/0/Alarm/Morning
-
findUniqueParents
final static List<String> findUniqueParents(Context context, Collection<String> folderFullPaths)
Given the following
folderFullPaths:/storage/9016-4EF8/Downloads/storage/9016-4EF8/Downloads/Archive/storage/9016-4EF8/Video/storage/9016-4EF8/Music/storage/9016-4EF8/Music/Favorites/Pop/storage/emulated/0/Musicprimary:Alarm/Morningprimary:Alarm
Then return:
/storage/9016-4EF8/Downloads/storage/9016-4EF8/Music/storage/9016-4EF8/Video/storage/emulated/0/Music/storage/emulated/0/Alarm
-
findInaccessibleStorageLocations
@WorkerThread() final static List<String> findInaccessibleStorageLocations(Context context, List<String> fullPaths)
-
getFreeSpace
final static Long getFreeSpace(Context context, String storageId)
-
getUsedSpace
final static Long getUsedSpace(Context context, String storageId)
-
getStorageCapacity
final static Long getStorageCapacity(Context context, String storageId)
-
getFileNameFromUrl
final static String getFileNameFromUrl(String url)
-
getEXTERNAL_STORAGE_AUTHORITY
final String getEXTERNAL_STORAGE_AUTHORITY()
-
getDOWNLOADS_FOLDER_AUTHORITY
final String getDOWNLOADS_FOLDER_AUTHORITY()
-
getMEDIA_FOLDER_AUTHORITY
final String getMEDIA_FOLDER_AUTHORITY()
-
getDOWNLOADS_TREE_URI
final String getDOWNLOADS_TREE_URI()
Only available on API 26 to 29.
-
getDOCUMENTS_TREE_URI
final String getDOCUMENTS_TREE_URI()
Only available on API 24 to 29.
-
getFILE_NAME_DUPLICATION_REGEX_WITH_EXTENSION
final Regex getFILE_NAME_DUPLICATION_REGEX_WITH_EXTENSION()
-
getFILE_NAME_DUPLICATION_REGEX_WITHOUT_EXTENSION
final Regex getFILE_NAME_DUPLICATION_REGEX_WITHOUT_EXTENSION()
-
getSD_CARD_STORAGE_ID_REGEX
final Regex getSD_CARD_STORAGE_ID_REGEX()
-
getSD_CARD_STORAGE_PATH_REGEX
final Regex getSD_CARD_STORAGE_PATH_REGEX()
-
-
-