OneDrive Integration in Android Applications
OneDrive (SkyDrive) is a commonly used cloud storage developed by Microsoft. Integrating one drive in to
Android applications is pretty simply now. Here, I will explain the steps to integrate this.
- Create an App in Microsoft Developer Center.
- Download the Picker attached with this article.
- Integrate picker to Android Application.
The above mentioned are the main steps for integrating One Drive file picker to Android applications. Now let's move on to the first set that is creating an App in Microsoft Developer Center,
- Go to Microsoft Developer Center.
- When prompted sign in to Microsoft account.
- Click on create application link and the page will appear like the following.
Please provide application name and click on I accept button
- Choose App Settings from the left pane and you will see a client ID and a client Secret values.
- Please copy the client ID from there we need this value in the Android Application.
You can configure many things here like Application Icon, url and soon. This is the end of first step, now download the Picker library project attached with this article and move to step three.
Integrate Picker to Android Application
In this step we will describe the configuration needed by your Android Application.
- Declare the client ID as public static final String ONEDRIVE_APP_ID = "00000000XXXXXXXX";
- On any button click we can call the following code to show the OneDrive picker.
- IPicker mPicker = Picker.createPicker(AppSettings.ONEDRIVE_APP_ID);
- mPicker.startPicking(PrivateMessagingWindow.this,LinkType.DownloadLink);
In the above code we will get the DownloadLink of the file which we will select, we also change LinkType to WebViewLink.
In the onActivityResult we will get the download link or webview link of the file we select, please see the code below,
- protected void onActivityResult(int requestCode, int resultCode, Intent data)
- {
-
- if (requestCode == ONEDRIVE_REQUESTCODE)
- {
-
- if (resultCode == RESULT_OK)
- {
- IPickerResult result = mPicker.getPickerResult(requestCode,
- resultCode, data);
- if (result != null)
- {
- String filename = null;
- filename = result.getName().toString();
- String url = result.getLink().toString();
- if (!TextUtils.isEmpty(filename) && !TextUtils.isEmpty(url))
-
- } else
- {
- Toast.makeText(Activity.this,
- "Failed to pick file", Toast.LENGTH_SHORT).show();
- }
- }
-
- }
Before you run this project please add Internet permission in the manifest file.
Read more articles on Android: