Google Cloud Platform

Run the Android Sample

The instructions below describe how to get the Android sample app running with the Mobile Backend using Eclipse. A similar methodology can be used with other IDEs, such as Android Studio. If you have not already, you must first Deploy the Backend.

Setup Eclipse with Google Plugin for Eclipse (GPE) and Android Developer Toolkit (ADT)

  1. Download and install Eclipse 4.2 IDE for Java.
  2. Install the Google Plugin for Eclipse (GPE) 4.2. Make sure you select the checkboxes for the following:
    • Developer Tools > Android Developer Tools
    • Google App Engine Tools for Android
    • Google Plugin for Eclipse
    • SDKs > Google App Engine Java SDK
    • Contact all update sites during install to find required software
  3. Restart Eclipse.
  4. Install the Android Developer Toolkit - select Eclipse > Window > Android SDK Manager to install the following:
  5. Connect an Android device running Android 4.0.3 or later, or use an Android Virtual Device (AVD) with a minimum API level of 15. The virtual devices are installed with the ADT plugin and can be accessed from Window -> Android Virtual Device Manager.

Configure the Android client app to run with the deployed backend

  1. Download the Android client zip file (or clone from GitHub repository) and unzip to a location of your choice.
  2. Import the unzipped Android project into Eclipse by selecting File > Import > Android > Existing Android Code Into Workspace and then supplying the directory you unzipped the client project.
  3. Ensure your new project is configured for a Google APIs target:
    1. Right click on the project in the Package Explorer view and choose Properties.
    2. Select the Android properties. Check that the target selected is Google APIs and shows an API level 15 or higher. If you have a lower level API, update your Android SDK (Window->Android SDK Manager) and install a higher API level to build the project against. Android Project Build Target page
  4. In the Android client project, locate the file src.com.google.cloud.backend.core.Consts.java and open it: Package Explorer
  5. Locate the following code:

    /* Set Project ID of your Google APIs Console Project.*/
    public static final String PROJECT_ID = "*** ENTER YOUR PROJECT ID ***";
    
  6. Replace *** ENTER YOUR PROJECT ID *** with the Project ID you created when you deployed the backend (we will change other values in this file in the next tutorial).

  7. Click Save to save your changes and build the project.

Running the Sample

  1. If you are using a physical Android device, make sure Development mode is enabled and the device is connected to your computer via USB.
  2. If you are using an AVD emulator, select Windows > Android Virtual Device Manager and start an existing device or click New to create one, then start it: let the device completely finish its startup process.
  3. Right-click your project selected in the Package Explorer pane, and select Run As > Android Application.
  4. Wait a few moments for the to be transferred onto your device.
  5. Start the client app, then enter some text into it and click Send. The sent message will be echoed with a timestamp: Running guestbook app
  6. View the message in the DataStore using App Engine’s DataStore viewer. To do this:
    1. Return to the Cloud Console for your project.
    2. Click Cloud Datastore in the list of services available to your backend.
    3. Click Query.
    4. In the Kind pulldown menu, select Guestbook and click Run Query. All of your messages are shown in the returned list: Datastore viewer

The sample guestbook app is now running and connected to the backend.

Next

Enable push messaging so other clients are notified of new messsages.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.