Integrate OneDrive In Android Applications

OneDrive Integration in Android Applications

OneDrive (SkyDrive) is a commonly used cloud storage developed by Microsoft. Integrating one drive into Android applications is pretty simple now. Here, I will explain the steps to integrate this. 
  1. Create an App in Microsoft Developer Center.
  2. Download the Picker attached to this article.
  3. 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 the 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 the first step, now download the Picker library project attached to 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.
    1. IPicker mPicker = Picker.createPicker(AppSettings.ONEDRIVE_APP_ID);      
    2. mPicker.startPicking(PrivateMessagingWindow.this,LinkType.DownloadLink);  
    1. In the above code we will get the DownloadLink of the file which we will select, we also change LinkType to WebViewLink.
    2. In the onActivityResult we will get the download link or webview link of the file we select, please see the code below,
      1. protected void onActivityResult(int requestCode, int resultCode, Intent data)    
      2. {    
      4.         if (requestCode == ONEDRIVE_REQUESTCODE)    
      5.         {   
      7.             if (resultCode == RESULT_OK)     
      8.             {    
      9.                 IPickerResult result = mPicker.getPickerResult(requestCode,    
      10.                     resultCode, data);    
      11.                 if (result != null)    
      12.                 {    
      13.                     String filename = null;    
      14.                     filename = result.getName().toString();    
      15.                     String url = result.getLink().toString();    
      16.                     if (!TextUtils.isEmpty(filename) && !TextUtils.isEmpty(url))    
      17.                     //Here you will get the file name and url and you can do further processing here.    
      18.                 } else    
      19.                 {    
      20.                     Toast.makeText(Activity.this,    
      21.                         "Failed to pick file", Toast.LENGTH_SHORT).show();    
      22.                 }    
      23.             }     
      25.         }   
    3. Before you run this project please add Internet permission in the manifest file.
    Read more articles on Android