Last Updated: Dec 21, 2017

  1. dependencies {
  2. compile 'com.aliyun.dpa:oss-android-sdk:2.4.4'
  3. compile 'com.squareup.okhttp3:okhttp:3.4.1'
  4. compile 'com.squareup.okio:okio:1.9.0'
  5. }

Direct introduction of the JAR package

After you download the OSS Android SDK ZIP package, follow these steps (applicable to Android Studio and Eclipse):

  • Download the SDK package from the official website.

  • Unzip the SDK package to obtain the following JAR packages: aliyun-oss-sdk-android-x.x.x.jar, okhttp-3.x.x.jar, and okio-1.x.x.jar.

  • Import the three JAR packages to the libs directory.

Permission settings

The following are the Android permissions required by the OSS Android SDK. Make sure these permissions are already set in your AndroidManifest.xml file to let SDK work normally.

  1. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  2. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
  3. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
  4. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

Obfuscation settings

Add the following to the obfuscation configuration:

  1. -keep class** { *; }
  2. -dontwarn okio.**
  3. -dontwarn org.apache.commons.codec.binary.**

Descriptions of synchronous interfaces and asynchronous interfaces in the SDK

Because network requests are not allowed to be processed in the UI thread in mobile development, many interfaces of the SDK support both synchronous and asynchronous calls to handle the requests. The synchronous interface call blocks other requests while waiting for the returned results, whereas the asynchronous interface only requires a callback function at the request to return the requested execution results.

The UI thread does not support synchronous interface calls. ClientException or ServiceException is thrown in the event of an exception. ClientException indicates a local exception, such as a network exception or invalid parameters. ServiceException indicates a service exception returned by OSS, such as an authentication failure or a server error.

When an exception occurs during asynchronous request processing, the exception is handled by a callback function.

When an asynchronous interface is called, the function returns a task. You can cancel the task, wait till the task is finished, or obtain results directly. For example,

  1. OSSAsyncTask task = oss.asyncGetObejct(...);
  2. task.cancel(); // You can cancel the task
  3. task.waitUntilFinished(); // Wait till the task is finished
  4. GetObjectResult result = task.getResult(); // Block other requests and wait for the returned results

Note: The interface supports both the synchronous and asynchronous calling methods. For concision, examples of how to call important interfaces in synchronous and asynchronous modes are provided. For other interfaces, only the asynchronous mode is described.

Thank you! We've received your feedback.