This project is no longer actively developed or maintained.
For new work on this check out android-docs-samples.
This application is a HelloWorld Android sample application that connects to a HelloWorld Google Cloud Endpoints backend sample.
-
Deploy a Google Cloud Endpoints backend sample that this client app will use as an API server. Proceed with optional authentication steps during setup.
-
Install Android Studio.
-
Download code
git clone https://github.com/GoogleCloudPlatform/appengine-endpoints-helloendpoints-android.git
-
Import the project:
- Open AndroidStudio and choose "Import Project."
- Select the build.gradle file in the HelloEndpointsProject directory and use default values for the rest of the import screens.
- NOTE: If you recieve an import error indicating that "play-services", a required dependency, could not be found that is OK. It will be resolved by the following step.
-
Check dependencies (even if the project compiles) using the Android SDK Manager. Ensure the following packages are installed and up-to-date:
- Android Support Repository
- Android Support Library
- Google Play Services
- Google Repository
-
Close and reopen your project. Clean dependencies using the Build menu by choosing "Rebuild Project."
-
Update the file
HelloEndpointsProject/HelloEndpoints/src/main/java/com/google/api/services/helloworld/Helloworld.java
with the location of your deployed API.DEFAULT_ROOT_URL
should include your App Engine app ID. -
Deploy the Android App
- Deploy your app via normal Android deployment procedures.
NOTE: At this point you can deploy the app and all anonymous API calls will work. The authenticated API call will not work; continue on to configure the Android application to securely communicate with your backend sample.
-
Register an Android Application to access your Google Cloud Endpoints backend project.
- Navigate to the Google Cloud Console. Select the Google Cloud Endpoints Backend project that was deployed as in Step 1.
- Navigate to the "APIs & Auth," item of the left menu bar.
- Choose the "Credentials" submenu item.
- Click "Create new Client ID" and select "Installed Application" and "Android."
- Use com.google.devrel.samples.helloendpoints as the package name.
- Retrieve your debugging keystore fingerprint from ADB. On a Mac this
command would typically look like this with an empty password:
keytool -list -v -keystore ~/.android/debug.keystore
- Click "Create Client ID."
-
Associate your Google Cloud Endpoints backend project to the Android application.
- Update the file
HelloEngpoints/src/main/java/com/google/devrel/samples/helloendpoints/AppConstants.java
.WEB_CLIENT_ID
field should be updated with the web application client ID that is defined in the "APIs & Auth" -> "Credentials" screen of your Google Cloud Endpoints backend project. You will be using the Client ID specified for "Compute Engine and App Engine." - You will similarly need to update your Google Cloud Endpoints backend
sample with the Android application client ID as well. Do not forget to
recompile your backend app (such as with
mvn clean install
for the Java one).
- Update the file
-
Deploy the Android App
- Deploy your app via normal Android deployment procedures.
- You will need to use a version 17 or later "Google APIs" enabled AVD definition if you are using an emulator instead of a physical device. Physical devices need only Google Play (Services) installed to work.
-
A quick note about the Client IDs used above for Authentication. -Client IDs identify applications (client or backend) to Google. The authenticated APIs in this sample utilize OAuth2 authentication. OAuth2 tokens are issued to specific Client IDs and therefore the Client IDs can be used for restricting access to your APIs. -When you create a Google Cloud Console Project a default Client ID is created and named for use by the project. When you upload an App Engine project it uses that Client ID. This becomes the
WEB_CLIENT_ID
referenced in the Android/iOS/Backend samples. -When you register the iOS or Android Applications in the Google Cloud Console you are creating another Client ID. This Client ID is the one requesting an OAuth2 token from Google for authentication purposes. When the API is used in an authenticated manner an OAuth2 access token is sent and opened by Google Cloud Endpoints. The Client ID is extracted from the token and compared to the backend's declared acceptable Client ID list.