Android integration

Overview

Cloudinary is a cloud-based service that provides an end-to-end image and video management solution including uploads, storage, manipulations, optimizations and delivery. All your media resources are optimized and delivered through a fast CDN using industry best practices.

Using Cloudinary's Android SDK, you can perform smart image and video manipulations using code that integrates seamlessly with your existing Android application and deliver optimized and responsive media to your users.

The Cloudinary Android SDK requires Android 4.1 or higher.

Quick example

The following Cloudinary URL and corresponding Android code generates the image below including all of the following transformations:

  • A thumbnail crop to a size of 150x150 pixels using face detection gravity to automatically determine the location for the crop
  • Rotated 20 degrees
  • Sepia effect
  • Cloudinary logo overlay on the southeast corner (with a slight offset). The logo is scaled down to a 50 pixel width, with increased brightness, and partial transparency (opaqueness = 60%)
  • 10 degree rotation
  • Converted to and delivered in PNG format (the originally uploaded image was a JPG)

Android:
MediaManager.get().url().transformation(new Transformation()
  .width(150).height(150).gravity("face").radius(20).effect("sepia").crop("thumb").chain()
  .overlay("cloudinary_icon").gravity("south_east").x(5).y(5).width(50).opacity(60).effect("brightness:200").chain()
  .angle(10)).generate("front_face.png")
Example dynamic delivery URL

Android SDK features

Cloudinary provides a Android library with an easy-to-use API for further simplifying the integration.

  • Build URLs for image and video transformation & manipulation.
  • Direct uploading to the cloud from your application.
  • Upload policy options (upload only on non-metered networks, only when charging, etc) globally or per upload request.
  • Asynchronous upload with callbacks.
  • Automatic error handling for network disconnections, timeouts, etc.

Android capitalization and data type guidelines

When using the Android SDK, keep these guidelines in mind:

  • Parameter names: snake_case. For example: public_id
  • Classes: PascalCase. For example: MediaManager
  • Methods: camelCase. For example: upload
  • Pass parameter data as: Map

Getting started

This section describes the information you need to know for installing and setting up Android.

Installation

The following instructions detail the installation of the Cloudinary Android library. Use one of the following options:

Gradle installation

Add the following line of code within the dependencies section of your build.gradle file:

compile group: 'com.cloudinary', name: 'cloudinary-android', version: '1.20.0'

Maven installation

Add the following tag within the dependencies tag in your pom.xml file:

<dependency>
    <groupId>com.cloudinary</groupId>
    <artifactId>cloudinary-android</artifactId>
    <version>1.20.0</version>
</dependency>

Manual installation

Download the following 2 files and put them in your libs folder:

Setup

To use the Cloudinary Android library you have to configure at least your cloud_name. You can additionally define a number of optional configuration parameters if relevant. You can find your configuration parameters in the dashboard of our Management Console.

The entry point of the library is the MediaManager object. The MediaManager.init() method must be called before using the Android library, preferably in Application.onCreate(). Setting the configuration parameters can be done either when initializing the library, or by using the CLOUDINARY_URL meta-data property in the AndroidManifest.xml file.

Config with init

To set the configuration parameters programmatically while initializing the MediaManager, pass a HashMap with parameters as the second argument of the init method. For example:

Map config = new HashMap();
config.put("cloud_name", "myCloudName");
MediaManager.init(this, config);

Config with meta-data

Alternatively, you can add the CLOUDINARY_URL meta-data property to the AndroidManifest.xml file, within the application tag. For example:

<meta-data 
   android:name="CLOUDINARY_URL" 
   android:value="cloudinary://@myCloudName"/>

When using the meta-data property, no configuration is required when initializing the MediaManager:

MediaManager.init(this);

Sample project

The Android sample project uses Cloudinary's Android SDK to perform direct uploading with uploading progress indication and an image preview with advanced transformations.