English | 简体中文
The unofficial QingStor SDK for the platform Android.
This project is based on qingstor-sdk-java.
There are some differences between qingstor-sdk-android and qingstor-sdk-java:
- All of the methods which should have been called(onProgress() and onAPIResponse() etc.), will be called in the Android Main Thread.
- Replace
org.json:json:20140107
with Android's own. - Remove
org.yaml:snakeyaml:1.17
and related codes. - Add Downloader and Uploader management for Android.
- Add the method QingstorHelper#handleResponse() to handle the response of the callback.
You can see documents containing the complete package structure here: github pages.
Configure this dependency:
implementation 'com.chengww:qingstor-sdk-android:0.1.0'
Init QingstorHelper in your Application:
QingstorHelper.getInstance().init(this);
PS: Don't forget to register your Application in the manifest file.
Each independent API refers to qingstor-sdk-java.
You can use XXXAsync()/sendAsync()
, and the callbacks will be called in the Android Main Thread.
For example, there are some codes to list buckets.
EnvContext context = new EnvContext(accessKey, accessSecret);
QingStor qingStor = new QingStor(context);
qingStor.listBucketsAsync(null, new ResponseCallBack<QingStor.ListBucketsOutput>() {
@Override
public void onAPIResponse(QingStor.ListBucketsOutput output) {
try {
QingstorHelper.getInstance().handleResponse(output);
// Success
List<Types.BucketModel> buckets = output.getBuckets();
// TODO: Do something here
} catch (TaskException exception) {
// Error
ToastUtils.show(MainActivity.this, exception.getI18nHint());
}
}
});
List Objects:
EnvContext context = new EnvContext("accessKey","accessSecret");
QingStor stor = new QingStor(context);
Bucket bucket = stor.getBucket("bucketName", "pek3b");
Bucket.ListObjectsInput listObjectsInput = new Bucket.ListObjectsInput();
listObjectsInput.setLimit(100);
listObjectsInput.setDelimiter("/");
listObjectsInput.setPrefix(prefix);
bucket.listObjectsAsync(listObjectsInput, new ResponseCallBack<Bucket.ListObjectsOutput>() {
@Override
public void onAPIResponse(Bucket.ListObjectsOutput output) {
try {
QingstorHelper.getInstance().handleResponse(output);
// TODO: Do something here
} catch (TaskException e) {
ToastUtils.show(ObjectListActivity.this, e.getI18nHint());
}
}
});
PS: Do not download/upload objects as below codes shown, cause XXXAsync() calls in the main thread where cannot write objects.
// A wrong demonstration. Do not try codes below.
bucket.getObjectAsync("objectName", null, new ResponseCallBack<Bucket.GetObjectOutput>() {
@Override
public void onAPIResponse(Bucket.GetObjectOutput output) {
// Write the object into the storage here...
}
});
You should new a thread to get the object use a synchronous method or use the Downloader/Uploader in the android SDK.
See the demo for more sample information.
Checkout our releases and change logs for information about the latest features, bug fixes and new ideas.
If you are using R8 or ProGuard add the options from proguard-rules.pro.
The Apache License (Version 2.0, January 2004).