> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://contentful.com/developers/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://contentful.com/developers/docs/_mcp/server.

# Getting Started with Contentful and Android

> This guide will help you get started with your first basic hello world style Android app using Contentful with a demo space.

This guide will show you how to get started using our [Android client library](https://github.com/contentful/contentful.java) to consume content.

Contentful's Content Delivery API (CDA) is a read-only API for retrieving content from Contentful. All content, both JSON and binary, is fetched from the server closest to a user's location by using our global CDN.

We publish client libraries for various languages to make developing applications easier.

## Requirements

This tutorial assumes that you understand the [Contentful data model](/concepts/data-model).

## Authentication

For every request, clients [need to provide an API key](/references/authentication), which is created per space and used to delimit applications and content classes.

You can create an access token using the [Contentful web app](https://be.contentful.com/login) or the [Content Management API](/references/content-management-api/overview#/reference/api-keys/create-an-api-key).

## Create a new Android project

Create a new project in Android Studio using the 'Blank Activity' template, and name it whatever you wish.

## Dependencies and permissions

This guide uses [RXAndroid](https://github.com/ReactiveX/RxAndroid) in the examples, which allows you to fetch results without tying up the main Android thread.

To include the CDA client library, add the following lines to the *build.gradle* file:

```gradle
dependencies {
    // [...]
    compile 'com.contentful.java:java-sdk:9.0.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
}
```

Add the internet permission to the *AndroidManifest.xml* file so your app can access the Contentful APIs:

```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.demospaceexplorer" >

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

## Creating a client

Add the following code to the `onCreate` method to create a `CDAClient` that communicates with the Contentful APIs:

## Initialize the client

You need an API key and a space ID to initialize a client. You can use the API key and space ID pre-filled below from our example space or replace them with your own values.

```java
CDAClient client = CDAClient.builder()
  .setSpace("<space_id>")
  .setToken("<access_token>")
  .build();
```

Use the [Gson](https://github.com/google/gson) library to make JSON responses easier to read.

```java
Gson gson = new GsonBuilder().setPrettyPrinting().create();
```

## Fetching specific items

If you want to fetch a specific entry, use the `id` of the entry inside a `.one` method:

```java
client.observe(CDAEntry.class)
    .one("<entry_id>")
    .observeOn(AndroidSchedulers.mainThread())
    .subscribeOn(Schedulers.io())
    .subscribe(new Subscriber<CDAEntry>() {
      CDAEntry result;

      @Override public void onCompleted() {
        Log.i("Contentful", gson.toJson(result));
      }

      @Override public void onError(Throwable error) {
        Log.e("Contentful", "could not request entry", error);
      }

      @Override public void onNext(CDAEntry cdaEntry) {
        result = cdaEntry;
      }
    });
```

```
I/Contentful: CDAEntry{id='`<entry_id>`'}
```

## Fetching all data from a space

To fetch all entries, create a new observable that watches for changes, in this case, fetching all entries from the specified space with the `all` method and content type with the `where` method:

```java
client.observe(CDAEntry.class)
               .where("content_type", "<product_content_type_id>")
               .all()
               .observeOn(AndroidSchedulers.mainThread())
               .subscribeOn(Schedulers.io())
               .subscribe(new Subscriber<CDAArray>() {
                   CDAArray result;

                   @Override
                   public void onCompleted() {
                       for (CDAResource resource : result.items()) {
                           CDAEntry entry = (CDAEntry) resource;
                           Log.i("Contentful", entry.getField("productName").toString());
                       }
                   }

                   @Override
                   public void onError(Throwable error) {
                       Log.e("Contentful", "could not request entry", error);
                   }

                   @Override
                   public void onNext(CDAArray cdaArray) {
                       result = cdaArray;
                   }
               });
```

```
I/Contentful: Hudson Wall Cup
I/Contentful: SoSo Wall Clock
I/Contentful: Whisk Beater
I/Contentful: Playsam Streamliner Classic Car, Espresso
```

The `onNext` method saves the array of entries and the `onCompleted` method is called once all entries are fetched from the API. The `onError` method allows you to handle any problems.

[1]: https://github.com/contentful/contentful.java

[4]: /sdks/android/tutorials/getting-started-with-contentful-and-android/