Android SDK

The open-source Gravatar Android SDK by Automattic enables Android developers to seamlessly integrate Gravatar functionality into their applications. This SDK provides methods for fetching Gravatar images, managing Gravatar profiles, and leveraging the rich feature set that Gravatar offers.

Features

  • Download a Gravatar image using an email address or a URL.
  • Fetch a Gravatar profile through the Gravatar API using an email address.
  • Display a profile or an avatar through ready-to-use Jetpack Compose UI components.
  • Upload an Avatar to a Gravatar account using a wordpress.com access token.
  • Avatar URL calculator based on email and several query options.
  • Built-in image cache (it’s also possible to inject your own caching mechanism).

Installation

To begin using the Gravatar Android SDK in your Android projects, follow these initial setup steps:

Step 1: Create an API key

Follow the steps in the REST API documentation to create a Gravatar API key. You can use some features without an API Key, but you’ll receive limited information, and stricter rate limits may apply, so we highly encourage you to create one in the developers’ portal.

Step 2: Add the SDK to your Android project

  1. Add the Maven repositories
    Add the following to your root ‘build.gradle’ at the end of the repositories:
repositories {
    maven {
        url "https://a8c-libs.s3.amazonaws.com/android"
    }
    // Jitpack is used to fetch the uCrop library. Required only for gravatar-ui module.
    maven {
        url "https://jitpack.io"
        content {
            includeModule("com.github.yalantis", "ucrop")
        }
    }
}
  1. Add the dependency
    Add the following dependency to your module’s ‘build.gradle‘ file (replace '<version>' with the latest release tag of the SDK):
dependencies {
    implementation ("com.gravatar:gravatar:<version>")
    implementation ("com.gravatar:gravatar-ui:<version>")
}

  1. Sync Your Project
    After adding the dependencies, sync your project with Gradle to ensure all necessary files are downloaded and set up correctly.

Step 3: Initialize the SDK with the API key

There are many ways to store the Gravatar API key in your app. The best way to do this depends on your app’s architecture and requirements and how you’re already storing other sensitive information. Make sure to avoid hardcoding the API key in your app’s code and make sure to avoid storing it in a public repository.

One way to API key in your app by adding it to the local.properties file:

gravatar.api.key = REPLACE_ME

Then update your gradle file to read the API key from the local.properties file and put it in the generated BuildConfig class:

android {
    buildFeatures.buildConfig = true

    val properties = Properties()
    properties.load(FileInputStream(project.rootProject.file("local.properties")))
    buildConfigField("String", "GRAVATAR_API_KEY", "\"${properties["gravatar.api.key"]}\"")
}

Then you can access the API key in your app’s code (typically in your MainActivity class) like this:

Gravatar.initialize(BuildConfig.GRAVATAR_API_KEY)

Next steps

Our “Get Started” guide on GitHub outlines the key steps for integrating the SDK into your Android app and using it. Check it out to learn how to retrieve profile information and display it using our UI components.

Please refer to our exhaustive API documentation and our GitHub repository for more information on how to integrate this SDK in your app.

For more code examples, check out our demo app!

Please note that these documents reflect our most up-to-date developments, so they might not perfectly align with the exact version of our SDK you’re currently working with.



Last updated on: