Calling an Endpoints Framework from an Android App

Cloud Endpoints Frameworks v1 has been deprecated and will be
shut down on August 2, 2018. We recommend that you use the latest version of
this feature, which is renamed to
Cloud Endpoints Frameworks for
App Engine. This new version supports App Engine standard environment, provides lower
latency, and has better integration with App Engine. For more details, see
Migrating to 2.0.

This page describes how to call a backend API built with a Cloud Endpoints
Framework from an Android app.
Note: These instructions assume familiarity with Android
development and concepts including project setup, Activities and AsyncTasks
classes, shared preferences, Android permissions, and Intents. If you would like
to learn more about these concepts, refer to the
Android documentation and examples.

The above sample code looks up any shared preferences stored by the Android app
and attempts to find the name of the account the user would like to use to
authenticate to your application. If successful, the code creates a credentials
object and passes it into your service object. These credentials allow your
Android application to pass the appropriate token to your backend.

Notice that the code sample checks to see whether or not the Android app already
knows which account to use. If it does, the logical flow can continue on and run
the Android app. If the app doesn't know which account to use, the app should
display a login screen or prompt the user to
pick an account.

Finally, the sample creates a credentials object and passes it into the service
object. These credentials allow your Android application to pass the appropriate
token to your App Engine web app.

Using the account picker

Android provides an intent to select a user account. You can invoke this as
follows:

Testing an Android client against a local development server

You can test your client against a backend API running in production App Engine
at any time without making any changes. However, if you want to test your client
against a backend API running on the local development server, you'll need to change
one line of code in the client to point to the IP address of the machine running
the local development server.

Note: You can use either an Android AVD emulator,
or a physical device. However, physical devices must use the same Wi Fi as the system
running the local development server.

To make the required changes and test using the local dev server:

Note the IP address of the machine that is running the local dev server: you
need it when you add code to the Android client.

Important: If the backend API is Auth-protected, your client must provide
support as described above under
Adding Authentication Support with OAuth 2.0.
However, when running against the local dev server, no credentials page is
displayed in response to a user's attempt to sign in. Instead, the sign-on
simply occurs, granting the user access to the protected API, and the user returned is always example@example.com.