# Android SDK

[transloadit/android-sdk](https://github.com/transloadit/android-sdk)

## Install

The JARs can be downloaded manually from[Maven Central](https://search.maven.org/artifact/com.transloadit.android.sdk/transloadit-android).

**Gradle:**

![](/_next/static/media/copy.8f7d2926.svg?dpl=dpl_SZA2V8V5MijkxhQJ9F2PZPKTyh8p)

```groovy
implementation 'com.transloadit.android.sdk:transloadit-android:0.2.0'

```

**Maven:**

![](/_next/static/media/copy.8f7d2926.svg?dpl=dpl_SZA2V8V5MijkxhQJ9F2PZPKTyh8p)

```xml
<dependency>
  <groupId>com.transloadit.android.sdk</groupId>
  <artifactId>transloadit-android</artifactId>
  <version>0.2.0</version>
</dependency>

```

## Usage

All interactions with the SDK begin with the `com.transloadit.android.sdk.AndroidTransloadit` class.

### Authentication Methods

The SDK supports two authentication methods:

#### 1. Traditional Authentication (with Secret Key)

This is suitable for server-side or internal-only apps:

![](/_next/static/media/copy.8f7d2926.svg?dpl=dpl_SZA2V8V5MijkxhQJ9F2PZPKTyh8p)

```java
AndroidTransloadit transloadit = new AndroidTransloadit("YOUR_KEY", "YOUR_SECRET");

```

#### 2. Signature Authentication (recommended for production apps)

For production mobile apps, use a backend signature endpoint so the secret stays on your server:

![](/_next/static/media/copy.8f7d2926.svg?dpl=dpl_SZA2V8V5MijkxhQJ9F2PZPKTyh8p)

```java
SignatureProvider signatureProvider = new SignatureProvider() {
  @Override
  public String generateSignature(String paramsJson) throws Exception {
    // Fetch a precomputed Transloadit signature from your backend.
    return "sha384:...";
  }
};

AndroidTransloadit transloadit = new AndroidTransloadit("YOUR_KEY", signatureProvider);

```

### Create an Assembly

To create an assembly, you use the `newAssembly` method.

To use this functionality fully, implement the `AndroidAssemblyListener` interface.

![](/_next/static/media/copy.8f7d2926.svg?dpl=dpl_SZA2V8V5MijkxhQJ9F2PZPKTyh8p)

```java
public class MyAssemblyListener implements AndroidAssemblyListener {

  @Override
  public void onUploadFinished() {
    System.out.println("upload finished!!! waiting for execution ...");
  }

  @Override
  public void onUploadProgress(long uploadedBytes, long totalBytes) {
    System.out.println("uploaded: " + uploadedBytes + " of: " + totalBytes);
  }

  @Override
  public void onAssemblyFinished(AssemblyResponse response) {
    System.out.println("Assembly finished with status: " + response.json().getString("ok"));
  }

  @Override
  public void onUploadFailed(Exception exception) {
    System.out.println("upload failed :(");
    exception.printStackTrace();
  }

  @Override
  public void onAssemblyStatusUpdateFailed(Exception exception) {
    System.out.println("unable to fetch status update :(");
    exception.printStackTrace();
  }
}


```

And in your activity you can have something like this

![](/_next/static/media/copy.8f7d2926.svg?dpl=dpl_SZA2V8V5MijkxhQJ9F2PZPKTyh8p)

```java
public class MainActivity extends AppCompatActivity {

  private ProgressBar progressBar;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    progressBar = (ProgressBar) findViewById(R.id.progressBar);

    AndroidAssemblyListener listener = new MyAssemblyListener();

    AndroidTransloadit transloadit = new AndroidTransloadit("key", "secret");
    AndroidAssembly assembly = transloadit.newAssembly(listener, this /* activity context */);
    assembly.addFile(new File("path/to/file.jpg"), "file");

    Map<String, Object> stepOptions = new HashMap<>();
    stepOptions.put("width", 75);
    stepOptions.put("height", 75);
    stepOptions.put("resize_strategy", "pad");
    assembly.addStep("resize", "/image/resize", stepOptions);

    assembly.saveAsync();
  }
}


```

## Example

For fully working examples take a look at[examples/](https://github.com/transloadit/android-sdk/tree/main/examples).

## Documentation

See[Javadoc](https://javadoc.io/doc/com.transloadit.android.sdk/transloadit-android/latest/index.html)for full API documentation.
