plugin-googledrive-gms
Android OMH Storage - Google Drive (GMS)
Prerequisites
Ensure you have the following packages installed before proceeding with the integration:
(Replace <version> with the latest version number shown in the Maven Central badge above)
Installation
To integrate the Google Drive storage provider into your Android project, follow these steps:
1. Configure Maven Central repository
Ensure Maven Central is included as a repository in your root build.gradle file:
allprojects {
repositories {
mavenCentral()
}
}2. Add dependency for the Google Drive storage provider
Add the dependency for the Google Drive storage provider to your project's build.gradle file:
dependencies {
implementation("com.openmobilehub.android.storage:plugin-googledrive-gms:<version>")
implementation("com.openmobilehub.android.storage:plugin-googledrive-non-gms:<version>")
}Configuration
Console App
To access Google Drive APIs, follow these steps to obtain the Client ID:
Create an OAuth 2.0 Client ID Android application and specify your app's Package Name and SHA1 Fingerprint.
Secrets
To securely configure the Google Drive storage provider, add the following entry to your project's local.properties file:
GOOGLE_CLIENT_ID=<YOUR_GOOGLE_CLIENT_ID>Usage
Initializing
To interact with the Google Drive storage provider, you must first initialize both the OMH Auth Client and OMH Storage Client with the necessary configurations. This setup ensures compatibility with both GMS and non-GMS Android devices.
val omhAuthClient = OmhAuthProvider.Builder()
.addNonGmsPath("com.openmobilehub.android.auth.plugin.google.nongms.presentation.OmhAuthFactoryImpl")
.addGmsPath("com.openmobilehub.android.auth.plugin.google.gms.OmhAuthFactoryImpl")
.build()
.provideAuthClient(
context = context,
scopes = listOf(
"openid",
"email",
"profile",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.file"
),
clientId = "<YOUR_GOOGLE_CLIENT_ID>"
)
val omhStorageClient = OmhStorageProvider.Builder()
.addGmsPath(GoogleDriveGmsConstants.IMPLEMENTATION_PATH)
.addNonGmsPath(GoogleDriveNonGmsConstants.IMPLEMENTATION_PATH)
.build()
.provideStorageClient(omhAuthClient, context)Other methods
Interacting with the Google Drive storage provider follows the same pattern as other storage providers since they all implement the OmhStorageClient interface. This uniformity ensures consistent functionality across different storage providers, so you won’t need to learn new methods regardless of the storage provider you choose! For a comprehensive list of available methods, refer to the Getting Started guide.
Caveats
The methods
downloadFileanddownloadFileVersiondo not support Google Workspace documents (Google Docs, Google Sheets, and Google Slides). To download Google Workspace documents, please use theexportFilemethod to export the file to a supported format.
The method
createPermissionwill overridesendNotificationEmailparameter totruewhen creating permission withOWNERrole.
The method
updateFiledoes not support Google Workspace documents. It throws an error for Google Sheets and Slides and for Google Docs, it does not update the metadata (apart from file name) which can lead to unexpected behavior.
Escape Hatch
This plugin provides an escape hatch to access the native Google Drive Android SDK. This allows developers to use the underlying provider's API directly, should they need to access a feature of the provider that is not supported by the OMH plugin.
You can obtain the Drive client instances by casting the result of getProviderSdk to Drive:
import com.google.api.services.drive.Drive
...
omhStorageClient.getProviderSdk() as DriveLicense
See LICENSE