How to Upload Files to OneDrive for Business from an Android App
Question details
The user needs to learn how to develop an Android application that can upload files directly to OneDrive for Business.

- Product
- Microsoft Graph API
- Device & OS
- Android
- Scenario
- Developing a custom Android application that integrates with Microsoft cloud services for file storage.
- Observed behavior
- The user is looking for correct API endpoints, authentication methods, and sample resources to implement file uploads to OneDrive via Microsoft Graph.
Ensure you have an active Microsoft 365 developer account, access to the Azure portal for app registration, and basic knowledge of REST APIs and Android development.
Use Microsoft Graph API for File Uploads
This is the standard and recommended approach for interacting with OneDrive for Business in custom Android applications.
To upload files to OneDrive for Business, developers should utilize the Microsoft Graph API. This process involves registering your app in Azure AD to handle Microsoft identity services, obtaining an access token, and making a REST API call to upload the file content.
Go to the Azure portal and register your Android application to use Microsoft identity services. Ensure you grant the necessary delegated permissions, such as Files.ReadWrite.
Integrate the Microsoft Authentication Library (MSAL) for Android into your app. This will allow users to sign in and provide your app with a valid access token.
Include the obtained access token in the Authorization header of your HTTP request. To upload a file, make a PUT request to an endpoint like: PUT /drive/root:/path/to/file.txt:/content, placing the file content directly in the request body.
Review the Microsoft Graph Developer Center and GitHub repositories like the 'Android Microsoft Graph snippets' for code examples and implementation details.

Looking for an Office Suite with Seamless Cloud Integration?
While developing custom apps is great for specific needs, if you simply need a powerful mobile office solution to manage and edit files, try WPS Office. It natively supports OneDrive for Business and offers high compatibility with Microsoft Office formats in a lightweight app.
- 1. Install WPS Office: Download and install WPS Office from the Google Play Store on your Android device.
- 2. Access Cloud Services: Open the app, navigate to the 'Open' tab, and tap on 'Add Cloud Storage'.
- 3. Connect to OneDrive: Select 'OneDrive', sign in with your Microsoft credentials, and easily access or upload your documents directly within the app.

Frequently Asked Questions
What permissions do I need to upload files to OneDrive for Business via Microsoft Graph?
Your registered application requires delegated permissions such as Files.ReadWrite or Files.ReadWrite.All to successfully upload and modify files in a user's OneDrive for Business account.
How do I upload files larger than 4MB using Microsoft Graph?
For files exceeding 4MB, you cannot use the simple PUT method. Instead, you must use the createUploadSession endpoint to upload the file in manageable byte ranges.
Where can I find code snippets for Microsoft Graph on Android?
You can explore the Microsoft Graph Developer Center and search GitHub for official repositories like 'ms-identity-android-native' and 'android-java-snippets-rest-sample' to find ready-to-use code blocks.




