This document explains how to start developing with the Awareness API on Android. The Awareness API is part of Google Play services.
To use the Awareness API, you need a Google Account. If you already have an account, then you're all set. You may also want a separate Google Account for testing purposes.
Set up Google Play services
To access the Awareness API, your app's development project must include Google Play services. Download and install the Google Play services component via the SDK Manager and add the library to your project. For details, see the Android guide to setting up Google Play services.
Add your API key
If you haven't already enabled the Awareness API and obtained a Google API key, follow the steps in Signup and API keys to do so.
Add your API key to your app manifest as shown in the following code sample, replacing YOUR_API_KEY with your own API key:
<application> ... <meta-data android:name="com.google.android.awareness.API_KEY" android:value="YOUR_API_KEY"/> </application>
If you are getting place snapshots, declare the following:
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_API_KEY" />
If you are getting beacon snapshots or using beacon fences, declare the following:
<meta-data android:name="com.google.android.nearby.messages.API_KEY" android:value="YOUR_API_KEY" />
Declare Android permissions in AndroidManifest.xml
Your app must declare permissions for each API method that is used. The required permissions vary depending on the API methods and fence types used by your app.
See Required Permissions for more information.
Connect to the Awareness API
To connect to the Awareness API, you must create an instance of the Google Play
Services API client. In your fragment's or activity's
method, create an instance of the Google API Client using
Use the builder to add the Awareness API, as shown in the following code sample:
android.content.Context context; GoogleApiClient client = new GoogleApiClient.Builder(context) .addApi(Awareness.API) .build(); client.connect();