> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Android quick start


[readme-version-support-link]:https://github.com/cloudinary/cloudinary_android#version-support
This quick start lets you get an end-to-end implementation up and running using the Android SDK in 10 minutes or less.

#### Prerequisites **To perform this quick start, you'll need:**

* A Cloudinary account. If you don't have one yet, you can quickly [register for free](https://cloudinary.com/users/register_free).
* Your product environment credentials. You can find your [credentials](product_environment_settings#api_keys) on the [API Keys](https://console.cloudinary.com/app/settings/api-keys) page of the Cloudinary Console Settings. 
  * To use your **API environment variable**, copy the provided format and replace the `<your_api_key>` and `<your_api_secret>` placeholders with the actual values found on the page. Your cloud name will already be correctly included in the format.
* A working Android development environment with a [supported version][readme-version-support-link] of Android.

> **NOTES**:
>
> * This quick start is designed for quick onboarding.  It doesn't necessarily employ coding best practices and the code you create here isn't intended for production.  

> * If you aren't familiar with Cloudinary, you may want to first take a look at the [Developer Kickstart](dev_kickstart) for a hands-on, step-by-step introduction to Cloudinary features. You may also find our [Glossary](cloudinary_glossary) helpful to understand Cloudinary-specific terminology.> **NOTE**: The Android SDK is Java based. If you are using Kotlin to develop your Android app, see the [Kotlin SDK integration guide](kotlin_integration).
## 1. Set up and configure

You need to complete some initial project set up and configuration. The quick start assumes you're using Android Studio as your IDE.

### Create a new Empty Views Activity project

Create a new app project and select Empty Views Activity from the list of templates. Give your app a name, update the package name to `com.cloudinary.cloudinaryquickstart`, and select Java as your language.

### Add the Cloudinary Android SDK and other modules

Add the dependencies for the Cloudinary SDK, Glide modules, and navigation dependencies to your **build.gradle.kts** file in the app directory. You also need to set `viewBinding` to true.

In the `dependencies` section of your file, add the following:

build.gradle.kts

```
implementation("com.cloudinary:cloudinary-android:3.0.2")
implementation("com.github.bumptech.glide:glide:4.16.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.navigation:navigation-fragment:2.7.7")
implementation("androidx.navigation:navigation-ui:2.7.7")

```

In the `Android` section of your file, add the following:

build.gradle.kts

```
buildFeatures {
    viewBinding = true
}

```

### Import the dependencies

In your **MainActivity** class, add the import statements for the Cloudinary SDK and other modules:

MainActivity.java

```android
package com.cloudinary.cloudinaryquickstart;

import android.net.Uri;
import android.os.Bundle;

import com.bumptech.glide.Glide;
import com.cloudinary.Transformation;
import com.cloudinary.android.MediaManager;
import com.cloudinary.android.callback.ErrorInfo;
import com.cloudinary.android.callback.UploadCallback;

import androidx.appcompat.app.AppCompatActivity;

import android.util.Log;

import com.cloudinary.cloudinaryquickstart.databinding.ActivityMainBinding;

import java.util.HashMap;
import java.util.Map;
```

### Configure Cloudinary

Update your `MainActivity` class, defining your cloud name, creating an `initCloudinary` method and initializing it in the `onCreate` method.

MainActivity.java

```android

public class MainActivity extends AppCompatActivity {

    private String cloudName = "<your_cloud_name>";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initCloudinary();
    }

    private void initCloudinary() {
        Map config = new HashMap();
        config.put("cloud_name", cloudName);
        MediaManager.init(this, config);
    }
}

```

More info about configuration...

You can set any [configuration parameters](cloudinary_sdks#configuration_parameters) in this way.

### Update layout views and manifest

In your resource directory, under layouts, open the **activity_main.xml** view in code view. Copy and paste the following code, replacing the existing contents of the file:

activity_main.xml

```xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize" />

    </com.google.android.material.appbar.AppBarLayout>

    <include
        android:id="@+id/main_content"
        layout="@layout/content_main" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
```

In the same directory, create a new file called **content_main.xml** and add the following XML code:

content_main.xml

```xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/generated_imageview"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/uploaded_imageview"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintDimensionRatio="W,1:1" />

    <ImageView
        android:id="@+id/uploaded_imageview"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/generated_imageview"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintDimensionRatio="W,1:1" />

</androidx.constraintlayout.widget.ConstraintLayout>

```

The above layouts define where to render the uploaded and transformed images in the view.

In **AndroidManifest.xml**, copy and paste the following code:

AndroidManifest.xml

```xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.CloudinaryQuickStart"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.CloudinaryQuickStart">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
```

## 2. Upload an image

Before adding your upload code:

1. Download the following [image](https://raw.githubusercontent.com/adimiz1/docs_ios_sample/master/docs_ios_sample_app/Assets.xcassets/cloudinary_logo.imageset/cloudinary_logo.png) and add it to the `drawable` resource folder.
2. Create an unsigned [upload preset](https://console.cloudinary.com/app/settings/upload/presets) (you can use the default settings) or use an existing unsigned preset. See the [upload presets guide](upload_presets) for more information.

Now copy and paste the code below which:

* Creates a variable for your unsigned upload preset (update this to the name of your newly created preset). 
* Defines and inflates view binding for the activity.
* Creates an `uploadImage` method.

Update **MainActivity.java** making sure to replace any variable placeholders:

MainActivity.java

```android

public class MainActivity extends AppCompatActivity {

    private String cloudName = "<your_cloud_name>";

    private String uploadPreset = "<your_upload_preset>"; //NEW - Name of unsigned upload preset";

    private ActivityMainBinding binding; //New - Activity binding

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater()); // New - inflate view binding
        initCloudinary();
        uploadImage(); // New - call upload image method
    }

    private void initCloudinary() {
        Map config = new HashMap();
        config.put("cloud_name", cloudName);
        MediaManager.init(this, config);
    }
    // New - upload image function
    private void uploadImage() {
        Uri uri = Uri.parse("android.resource://com.cloudinary.cloudinaryquickstart/drawable/cloudinary_logo");
        MediaManager.get().upload(uri).unsigned(uploadPreset).callback(new UploadCallback() {
            @Override
            public void onStart(String requestId) {
                Log.d("Cloudinary Quickstart", "Upload start");
            }

            @Override
            public void onProgress(String requestId, long bytes, long totalBytes) {
                Log.d("Cloudinary Quickstart", "Upload progress");
            }

            @Override
            public void onSuccess(String requestId, Map resultData) {
                Log.d("Cloudinary Quickstart", "Upload success");
                String url = (String) resultData.get("secure_url");
                Glide.with(getApplicationContext()).load(url).into(binding.mainContent.uploadedImageview);
            }

            @Override
            public void onError(String requestId, ErrorInfo error) {
                Log.d("Cloudinary Quickstart", "Upload failed");
            }

            @Override
            public void onReschedule(String requestId, ErrorInfo error) {

            }
        }).dispatch();
    }

}
```

More info about upload...

* See the `upload` method of the [Upload API](image_upload_api_reference#upload) for more optional parameters.
* Learn more about [uploading assets](upload_images) in general.

## 3. Transform an image

Copy and paste the following code, which:

* Additionally defines a public ID of an image to transform (you can use a sample from your account, such as `cld-sample-5`)
* Adds a variable for your URL. 
* Adds a method for generating a Cloudinary URL and setting the image view.
* Sets up the content view and toolbar.

Update **MainActivity.java** making sure to replace any variable placeholders:

MainActivity.java

```android
package com.cloudinary.cloudinaryquickstart;

import android.net.Uri;
import android.os.Bundle;

import com.bumptech.glide.Glide;
import com.cloudinary.Transformation;
import com.cloudinary.android.MediaManager;
import com.cloudinary.android.callback.ErrorInfo;
import com.cloudinary.android.callback.UploadCallback;

import androidx.appcompat.app.AppCompatActivity;

import android.util.Log;

import com.cloudinary.cloudinaryquickstart.databinding.ActivityMainBinding;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private String cloudName = "<your_cloud_name>";
    private String uploadPreset = "<your_upload_preset>";
    private String url; // New - variable for URL
    private String publicId = "<your_public_id>"; // New - Public Id for image to transform
    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        // New - setting up content view and toolbar
        setContentView(binding.getRoot());
        binding.toolbar.setTitle("Cloudinary Quickstart");
        setSupportActionBar(binding.toolbar);

        initCloudinary();
        uploadImage();
        generateUrl(); // New - call method to generate URL
    }

    private void initCloudinary() {
        Map config = new HashMap();
        config.put("cloud_name", cloudName);
        MediaManager.init(this, config);
    }

    private void uploadImage() {
        Uri uri = Uri.parse("android.resource://com.cloudinary.cloudinaryquickstart/drawable/cloudinary_logo");
        MediaManager.get().upload(uri).unsigned(uploadPreset).callback(new UploadCallback() {
            @Override
            public void onStart(String requestId) {
                Log.d("Cloudinary Quickstart", "Upload start");
            }

            @Override
            public void onProgress(String requestId, long bytes, long totalBytes) {
                Log.d("Cloudinary Quickstart", "Upload progress");
            }

            @Override
            public void onSuccess(String requestId, Map resultData) {
                Log.d("Cloudinary Quickstart", "Upload success");
                String url = (String) resultData.get("secure_url");
                Glide.with(getApplicationContext()).load(url).into(binding.mainContent.uploadedImageview);
            }

            @Override
            public void onError(String requestId, ErrorInfo error) {
                Log.d("Cloudinary Quickstart", "Upload failed");
            }

            @Override
            public void onReschedule(String requestId, ErrorInfo error) {

            }
        }).dispatch();
    }

    //New - method for generating Cloudinary URL for given Public Id
    private void generateUrl() {
        url = MediaManager.get().url().transformation(new Transformation().effect("sepia")).generate(publicId);
        Glide.with(this).load(url).into(binding.mainContent.generatedImageview);
    }

}

```

More info about transformations...

* When the image gets delivered via this URL, you see a transformed version of the image (the original remains intact).
* The applied transformation in this case is applying a sepia effect.
* See the [transformation reference](transformation_reference) for details of all transformations.

## 4. Run your code

Run your app. You should see your two images, one being the Cloudinary logo that you uploaded and the other a transformed image for the public ID that you set.

![Android quickstart main view](https://cloudinary-res.cloudinary.com/image/upload/f_auto/q_auto/docs/android_quickstart.png "width: 400, popup:true, thumb: w_400/dpr_2.0")

## View the completed code

You can find the full code example for this on [GitHub](https://github.com/adimiz1/android-quickstart).

## Next steps
* Learn more about the Android SDK by visiting the other pages in this SDK guide.
* Get comprehensive details about Cloudinary features and capabilities:
    * [Upload guide](upload_images): Provides details and examples of the upload options.
    * [Image transformations guide](image_transformations): Provides details and examples of the transformations you can apply to image assets.
    * [Video transformations guide](video_manipulation_and_delivery): Provides details and examples of the transformations you can apply to video assets.
    * [Transformation URL API Reference](transformation_reference): Provides details and examples of all available transformation parameters. 
    * [Admin API guide](admin_api): Provides details and examples of the methods available for managing and organizing your media assets.
Take a look at the [Android sample project](android_sample_projects) for a more comprehensive example using the Cloudinary Android SDK.
