Mobile CMS Guide for Android

JSON fueled, delivered by Cloud CMS





It's easy to plug Cloud CMS to provide backend services for your applications running on Google Android devices. This page provides details about how Android developers can plug Cloud CMS into their new or existing mobile applications to quickly spin up apps using their preferred Java IDE and SDK.

Getting Started

Download the Cloud CMS Java driver

The Cloud CMS Java driver handles all of the HTTPS calls, data conversions, OAuth2 authorization handshakes and any and all interaction with the Cloud CMS platform in a secure manner.

To get the latest version of the driver, please visit the

Android CMS Hello World

Grab a simple Hello World application using our baseline code at

NOTE: You can either grab a copy of the standalone driver (which is larger but bundles all dependencies into a single JAR file) or utilize Maven (or an equivalent dependency manager) to pull in all of the individual JAR dependencies as you see fit.

Build Process

1) Open your IDE for Android and create a new Android application project with an empty activity. In this guide, we will use Intellij as our IDE. If you prefer to use Eclipse, please follow instructions in the Android’s Building Your First App Guide.

2) Copy the Cloud CMS Java Driver into the libs directory and make sure the libs directory is included in the project libraries.

3) Edit AndroidManifest.xml (which is under project root directory) and add the user permission for android.permission.INTERNET.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cloudcms.android"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<activity android:name="HelloWorldActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

4) Edit the activity java class ( HelloWorldActivity.java ) and add the code for making connection to the Cloud CMS platform.Once the connection is made using the provided credentials, it will then print out a welcome message with the name of the authenticated user.

package com.cloudcms.android;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.gitana.platform.client.AuthInfo;
import org.gitana.platform.client.Gitana;
import org.gitana.platform.client.support.DriverContext;
public class HelloWorldActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
try {
Gitana gitana = new Gitana("...","...");
// authenticate
gitana.authenticate("demo", "demo");
// check driver properties
AuthInfo authInfo = DriverContext.getDriver().getAuthInfo();
// print out some things about the principal
TextView text = new TextView(this);
text.setText("Hello " + authInfo.getPrincipalName() + ", Welcome to Cloud CMS!");
setContentView(text);
} catch (Exception e) {
e.printStackTrace();
}
}
}

5) Run the project in an Android emulator and we should have a screen which looks like this.

If you haven't already visited the Google Android Developer site, we recommend that you do so to become familiar with Android, the Java SDK and the tools required to build Android applications.

Sign up for Cloud CMS

If you already have a Cloud CMS subscription, you can skip ahead.
Otherwise, be sure to sign up for a trial account first, in order to use Cloud CMS.

API Keys

Every mobile app or web site that you build will need to have a set of API Keys that it will use to connect to your Cloud CMS platform on behalf of your code. These API keys consist of client and user key/secret pairs. You can generate a set of keys using the following steps:

  1. Log in to your Cloud CMS tenant at https://<yourdomain>.cloudcms.net
  2. Click on Developers

You will now see your API Keys for all of your platform's Application instances.
You can create as many Application instances as you'd like and each will have their own set of API Keys.

For more information, visit Configuring your API Keys.