Contentful logo

Contentful Community

Getting Started with Contentful and Android

The documentation for Android (as of 29/11/2017) uses an old version of the Java SDK:
https://www.contentful.com/developers/docs/android/tutorials/getting-started-with-contentful-and-android/

Here is the updated code you will need to use:

build.gradle

compile 'com.contentful.java:java-sdk:8.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.7'

MainActivity.java

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

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

        @Override
        public void onComplete() {
        }

        @Override
        public void onError(Throwable error) {
        }

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

For more details see the documentation on GitHub:


For changes made from Contentful Java SDK 7 to 8:

Hey,

thanks again for noticing. I’ll be updating the documentation, and it should be updated soon™.

Mario