onedrive for android,GitHub - OneDrive/onedrive-sdk-android: OneDrive SDK for Android!

OneDrive SDK for Android

68747470733a2f2f6170692e62696e747261792e636f6d2f7061636b616765732f6f6e6564726976652f4d6176656e2f6f6e6564726976652d73646b2d616e64726f69642f696d616765732f646f776e6c6f61642e737667

68747470733a2f2f7472617669732d63692e6f72672f4f6e6544726976652f6f6e6564726976652d73646b2d616e64726f69642e7376673f6272616e63683d6d6173746572

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 "";

}

@Override

public String[] getScopes() {

return new String[] { "onedrive.appfolder" };

}

}

final ADALAuthenticator adalAuthenticator = new ADALAuthenticator() {

@Override

public String getClientId() {

return "";

}

@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 callback = new DefaultCallback(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() {

@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() {

@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

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 opencode@microsoft.com with any additional questions or comments.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值