Getting Started with Android OMH Storage
Android OMH Storage is a project that integrates various cloud storage providers into Android applications. It offers a unified API to work with different storage providers.
Prerequisites
Before integrating any storage provider into your Android project, ensure you meet the following requirements:
- Gradle version: 7.0 or higher
- Android API level: 23(GoogleDrive, Dropbox), 26(OneDrive) or higher
Installation
To integrate a storage provider into your Android project, follow the specific steps for each provider:
Usage
💡 GOOD TO KNOW
Any operation you can perform on files can also be applied to folders.
Get root folder path
Retrieves the root folder path of the storage service. Useful when you want to list files in the root folder.
val rootPath = omhStorageClient.rootFolder
List files
Lists files from a specific folder.
val files = omhStorageClient.listFiles(parentId = "folderId")
Search files
Lists files with names containing the specified query value.
val searchResults = omhStorageClient.search(query = "fileName")
Create folder
Creates a folder in a specific folder.
val newFile = omhStorageClient.createFolder(
name = "fileName",
parentId = "folderId"
)
Create file (with mime type)
Creates a file in a specific folder.
val newFile = omhStorageClient.createFileWithMimeType(
name = "fileName",
mimeType = "fileMimeType",
parentId = "folderId"
)
Create file (with extension)
Creates a file in a specific folder.
val newFile = omhStorageClient.createFileWithExtension(
name = "fileName",
extension = "ext",
parentId = "folderId"
)
Update file
Updates a remote file with the content of a local file.
val updatedFile = omhStorageClient.updateFile(
localFileToUpload = File("localFilePath"),
fileId = "fileId"
)
Delete file
Moves a file with the given file ID in the trash.
omhStorageClient.deleteFile(id = "fileId")
Permanently delete file
Permanently deletes a file with the given file ID.
omhStorageClient.permanentlyDeleteFile(id = "fileId")
Upload file
Uploads a local file to a specific folder.
val uploadedFile = omhStorageClient.uploadFile(
localFileToUpload = File("localFilePath"),
parentId = "folderId"
)
Download file
Downloads a file with the given file ID.
val fileContent = omhStorageClient.downloadFile(fileId = "fileId")
Export file
Exports a provider application file with the given file ID to a specified MIME type.
val exportedFileContent = omhStorageClient.exportFile(
fileId = "fileId",
exportedMimeType = "desiredMimeType"
)
Get file metadata
Retrieves the metadata of a file with the given file ID.
val fileMetadata = omhStorageClient.getFileMetadata(fileId = "fileId")
For more details on file metadata support for each provider, please refer to the File metadata documentation.
Get file versions
Retrieves the versions of a file with the given file ID.
val fileVersions = omhStorageClient.getFileVersions(fileId = "fileId")
Download file version
Downloads a specific version of a file.
val versionContent = omhStorageClient.downloadFileVersion(
fileId = "fileId",
versionId = "versionId"
)
Get file permissions
Lists the permissions of a file with the given file ID.
val permissions = omhStorageClient.getFilePermissions(fileId = "fileId")
Create file permission
Creates a permission for a file.
val userPermission = OmhCreatePermission.CreateIdentityPermission(
OmhPermissionRole.WRITER,
OmhPermissionRecipient.User("test@email.com")
)
val newPermission = omhStorageClient.createPermission(
fileId = "fileId",
permission = userPermission,
sendNotificationEmail = true,
emailMessage = "Optional message"
)
For more details on file permissions support for each provider, please refer to the File permissions documentation.
Update file permission
Updates the role of a permission in a file.
val updatedPermission = omhStorageClient.updatePermission(
fileId = "fileId",
permissionId = "permissionId",
role = OmhPermissionRole.ROLE
)
Delete file permission
Deletes a permission with the given permission ID from a file.
omhStorageClient.deletePermission(
fileId = "fileId",
permissionId = "permissionId"
)
Get file URL
Retrieves the file URL.
val webUrl = omhStorageClient.getWebUrl(fileId = "fileId")
Get folder size
Recursively calculates the total size of files in the specified folder, in bytes.
val totalFolderSize = omhStorageClient.folderSize(folderId = "folderId")
Get storage quota
Retrieves the storage quota allocated by the storage provider, in bytes. It is entirely depends on storage provider’s calculations, so actual figures may differ.
val quotaAllocated = omhStorageClient.getStorageQuota()
Get storage usage
Retrieves the storage quota currently in use, in bytes. It is entirely depends on storage provider’s calculations, so actual figures may differ.
val quotaUsed = omhStorageClient.getStorageUsage()
For a more in depth view on the available methods, access the Reference API.
Sample app
Explore the sample app included in the repository to see the implementation of storage with Google Drive and other storage providers. The sample app demonstrates the integration and usage of the various storage providers, providing a practical example to help you get started quickly.