Module plugin-onedrive
Android OMH Storage - OneDrive
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 OneDrive 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 OneDrive storage provider
Add the dependency for the OneDrive storage provider to your project’s build.gradle file:
dependencies {
implementation("com.openmobilehub.android.storage:plugin-onedrive-gms:<version>")
}
Configuration
Console App
To access Microsoft APIs, follow these steps to obtain the MSAL Configuration:
- Create a new app in Microsoft Azure.
- Add the Android platform and specify your Package Name and Signature Hash for your app.
- Copy the MSAL Configuration into a newly created JSON file named ms_auth_config.json and place it in the src/main/res/raw directory.
- In the ms_auth_config.json file, add a new key
"account_mode"with the value"SINGLE".
Secrets
To securely configure the OneDrive storage provider, add the following entry to your project’s local.properties file:
MICROSOFT_SIGNATURE_HASH=<YOUR_MICROSOFT_SIGNATURE_HASH>
Usage
Initializing
To interact with the OneDrive storage provider, you must first initialize both the OMH Auth Client and OMH Storage Client with the necessary configurations.
val omhAuthClient = MicrosoftAuthClient(
configFileResourceId = R.raw.ms_auth_config,
context = context,
scopes = arrayListOf("User.Read", "Files.ReadWrite.All"),
)
val omhStorageClient = OneDriveOmhStorageFactory().getStorageClient(omhAuthClient)
Other methods
Interacting with the OneDrive 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
When updating a file, if the new file has a different name than the updated file, two additional versions might sometimes appear in the system. One version comes from updating the content of the file, and the other comes from updating the file name. However, this behavior is non-deterministic, and sometimes only one new version is added. This is why it is listed under the Caveats section.
The Sharing Links permissions are not supported.
When creating permission for a user with a given email address, there has to be a Microsoft Account assigned to this email. Otherwise, an exception will be thrown with the user message: “Some users in the request cannot be invited securely”. This is caused by
requireSignInflag being set to true in the invitation request. The library does that as the Sharing Links are not yet supported, and for some accounts, when inviting users without a Microsoft Account, a sharing link will be created instead of permission.
The search query takes several fields including filename, metadata, and file content when searching.
Escape Hatch
This plugin provides an escape hatch to access the native OneDrive 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 OneDrive client instances by casting the result of getProviderSdk to GraphServiceClient:
import com.microsoft.graph.serviceclient.GraphServiceClient
...
omhStorageClient.getProviderSdk() as GraphServiceClient
License
- See LICENSE