• This repository has been archived on 02/Oct/2024
  • Stars
    star
    148
  • Rank 249,930 (Top 5 %)
  • Language
    Java
  • License
    Other
  • Created about 9 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OneDrive SDK for Android!

OneDrive SDK for Android

Download Build Status

Integrate the OneDrive API into your Android application!

1. Installation

1.1 Install AAR via Gradle

Add the maven central repository to your projects build.gradle file then add a compile dependency for com.onedrive.sdk:onedrive-sdk-android:1.3+

repository {
    jcenter()
}

dependency {
    // Include the sdk as a dependency
    compile ('com.onedrive.sdk:onedrive-sdk-android:1.3+') {
        transitive = false
    }

    // Include the gson dependency
    compile ('com.google.code.gson:gson:2.3.1')

    // Include supported authentication methods for your application
    compile ('com.microsoft.services.msa:msa-auth:0.8.+')
    compile ('com.microsoft.aad:adal:1.1.+')
}

2. Getting started

2.1 Register your application

Register your application by following these steps.

2.2 Set your application Id and scopes

The OneDrive SDK for Android comes with Authenticator objects that have already been initialized for OneDrive with Microsoft accounts and Azure Activity Directory accounts. Replace the current settings with the required settings to start authenticating.

Application that authenicate via MSA need to have a scope of access defined to use features on OneDrive. If your application is being used in for OneDrive for business AAD will need the administrators consent for your application to communicate with OneDrive.

Note that your msa-client-id and adal-client-id should look be in GUID format like 00000000-0000-0000-0000-000000000000. For legacy MSA application, the msa-client-id should look like 0000000000000000.

final MSAAuthenticator msaAuthenticator = new MSAAuthenticator() {
    @Override
    public String getClientId() {
        return "<msa-client-id>";
    }

    @Override
    public String[] getScopes() {
        return new String[] { "onedrive.appfolder" };
    }
}

final ADALAuthenticator adalAuthenticator = new ADALAuthenticator() {
    @Override
    public String getClientId() {
        return "<adal-client-id>";
    }

    @Override
    protected String getRedirectUrl() {
        return "https://localhost";
    }
}

2.3 Get a OneDriveClient object

Once you have set the correct application Id and scopes, you must get a OneDriveClient object to make requests against the service. The SDK will store the account information for you, but when a user logs on for the first time, it will invoke UI to get the user's account information.

final IClientConfig oneDriveConfig = DefaultClientConfig.createWithAuthenticators(
                                            msaAuthenticator,
                                            adalAuthenticator);
                                            
final DefaultCallback<IOneDriveClient> callback = new DefaultCallback<IOneDriveClient>(activity) {
            @Override
            public void success(final IOneDriveClient result) {
                // OneDrive client created successfully.
            }

            @Override
            public void failure(final ClientException error) {
                // Exception happened during creation.
            }
        };
        
final IOneDriveClient oneDriveClient = new OneDriveClient.Builder()
                                            .fromConfig(oneDriveConfig)
                                            .loginAndBuildClient(getActivity(), callback);

3. Make requests against the service

Once you have an OneDriveClient that is authenticated you can begin making calls against the service. The requests against the service look like our REST API.

Get the drive

To retrieve a user's drive:

oneDriveClient
    .getDrive()
    .buildRequest()
    .get(new ICallback<Drive>() {
  @Override
  public void success(final Drive result) {
    final String msg = "Found Drive " + result.id;
    Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT)
        .show();
  }
  ...
  // Handle failure case
});

Get the root folder

To get a user's root folder of their drive:

oneDriveClient
    .getDrive()
    .getRoot()
    .buildRequest()
    .get(new ICallback<Item>() {
  @Override
  public void success(final Item result) {
    final String msg = "Found Root " + result.id;
    Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT)
        .show();
  }
  ...
  // Handle failure case
});

For a general overview of how the SDK is designed, see overview.

4. Documentation

For a more detailed documentation see:

5. Issues

For known issues, see issues.

6. Contributions

The OneDrive SDK is open for contribution. Please read how to contribute to this project here.

7. Supported Android Versions

The OneDrive SDK for Android library is supported at runtime for Android API revision 15 and greater. To build the sdk you need to install Android API revision 23 or greater.

8. License

License

9. Third Party Notices

[Third Party Notices](THIRD PARTY NOTICES)

10. Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

More Repositories

1

onedrive-sdk-python

OneDrive SDK for Python! https://dev.onedrive.com
Python
1,077
star
2

onedrive-api-docs

Official documentation for the OneDrive API
TypeScript
453
star
3

onedrive-sdk-csharp

OneDrive SDK for C#! https://dev.onedrive.com
C#
294
star
4

onedrive-explorer-js

OneDrive sample application for JavaScript.
HTML
113
star
5

onedrive-sdk-ios

OneDrive SDK for iOS
Objective-C
101
star
6

onedrive-picker-android

Sample application for OneDrive file picker SDK for Android
Java
100
star
7

onedrive-sample-apibrowser-dotnet

C#
77
star
8

onedrive-explorer-win

OneDrive API Explorer sample code for Windows / C#
64
star
9

samples

Contains samples, scenarios, and guidance for integrating with OneDrive and SharePoint drives, drive items, and files.
C#
56
star
10

onedrive-explorer-android

OneDrive Explorer for Phone and Tablets!
Java
55
star
11

apidoctor

Application for validating API documentation and generating test cases
C#
40
star
12

onedrive-community-samples

Repository for community samples in OneDrive GitHub organization.
34
star
13

onedrive-admin-scripts

OneDrive Scripts for Administrators
PowerShell
31
star
14

o365-markdown-file-handler-v2

File handler for Office 365 to enable previewing and viewing markdown documents
C#
27
star
15

onedrive-texteditor-js

Simple single-page JavaScript app for editing text files
JavaScript
26
star
16

markdown-scanner

Application for scanning markdown documentation and generating test cases for APIs.
C#
23
star
17

onedrive-sdk-dotnet-msa-auth-adapter

C#
23
star
18

onedrive-webhooks-aspnet

Sample ASP.NET MVC application that receives webhooks from OneDrive and OneDrive for Business
JavaScript
19
star
19

graph-sample-photobrowser-uwp

The Microsoft OneDrive Graph Photo Browser sample is a Windows Universal app that uses the OneDrive SDK for C#/.NET. The sample app displays only items that are images from a user's OneDrive. Note that this sample does not work with OneDrive for Business.
C#
17
star
20

onedrive-sample-sync-ios

OneDrive iOS Sync Sample App
Swift
13
star
21

onedrive-data-robot-azure-function

Sample code using Azure Functions with OneDrive webhooks
C#
11
star
22

onedrive-sample-photobrowser-uwp

C#
10
star
23

document-library-audio-transcription-robot-sample

Sample from Ignite 2017 talk, that uses the Speech API to transcribe audio files in a document library
C#
4
star
24

file-browser-demo

JavaScript
3
star
25

.github

Default Community Health Files for the OneDrive organization on GitHub
1
star