Signup and API keys

To use the Google Awareness API, you must add a Google API key to your app. The type of API key you need is an Android API key.

All Android apps are signed with a digital certificate for which you hold the private key. For more information about digital certificates, refer to the Android guide on how to sign your app.

Android API keys are linked to specific certificate-package pairs. You only need one key for each certificate, no matter how many users you have for the app.

Several steps are required for you to get a key for your app. They're described in detail in this guide, and are summarized as follows:

  1. Get information about your app's certificate.
  2. Register a project in the Google Developers console and add the User Context API as a service for the project.
  3. Request a key.
  4. Add the key to your app. To do so, add an element to your app manifest.

Find your app's certificate information

The API key is based on a short form of your app's digital certificate, known as its SHA-1 fingerprint. To display the SHA-1 fingerprint for your certificate, first ensure that you use the right certificate. You might have the following two certificates to choose from:

  • A debug certificate: The Android SDK tools generate this certificate automatically when you do a debug build. Only use this certificate with apps that you're testing. Don't attempt to publish an app that's signed with a debug certificate. The debug certificate is described in more detail in the Sign your debug build section in the Android developer documentation.
  • A release certificate: The Android SDK tools generate this certificate when you do a release build. You can also generate this certificate with the keytool program. Use this certificate when you're ready to release your app to the world.

For more information about keytool, see its Oracle documentation.

Debug certificate

Display the debug certificate fingerprint

Use the keytool program with the -v parameter to display a certificate's SHA-1 fingerprint. To do so, complete the following steps:

  1. Locate your debug keystore file. The file name is debug.keystore, and it's created the first time you build your project. By default, it's stored in the same directory as your Android Virtual Device (AVD) files:

    • OS X and Linux: ~/.android/
    • Windows Vista and Windows 7: C:\Users\your_user_name\.android\
  2. List the SHA-1 fingerprint:

    • For Linux or OS X, open a terminal window and enter the following:

      keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
    • For Windows Vista and Windows 7, run the following:

      keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

You should see output similar to the following:

Alias name: androiddebugkey
Creation date: Jan 01, 2013
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 4aa9b300
Valid from: Mon Jan 01 08:04:04 UTC 2013 until: Mon Jan 01 18:04:04 PST 2033
Certificate fingerprints:
     MD5:  AE:9F:95:D0:A6:86:89:BC:A8:70:BA:34:FF:6A:AC:F9
     SHA1: BB:0D:AC:74:D3:21:E1:43:07:71:9B:62:90:AF:A1:66:6E:44:5D:75
     Signature algorithm name: SHA1withRSA
     Version: 3
Release certificate

Display the release certificate fingerprint

Use the keytool program with the -v parameter to display a certificate's SHA-1 fingerprint. To do so, complete the following steps:

  1. Locate your release certificate keystore file. There's no default location or name for the release keystore. If you don't specify one when you build your app for release, the build leaves your .apk unsigned and you have to sign it before you can publish it. For the release certificate, you also need the certificate's alias, the passwords for the keystore, and the certificate.
  2. Enter the following to list the aliases for all the keys in a keystore:

    keytool -list -keystore your_keystore_name
          
  3. Replace your_keystore_name with the fully qualified path and name of the keystore. Include the .keystore extension. Enter the keystore's password when prompted. Then, keytool displays all the aliases in the keystore.
  4. Enter the following at a terminal or command prompt:

          keytool -list -v -keystore your_keystore_name -alias your_alias_name
          
  5. Replace your_keystore_name with the fully qualified path and name of the keystore. Include the .keystore extension.
  6. Replace your_alias_name with the alias that you assigned to the certificate when you created it.

You should see output similar to the following:

Alias name: <alias_name>
Creation date: Feb 02, 2013
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 4cc9b300
Valid from: Mon Feb 02 08:01:04 UTC 2013 until: Mon Feb 02 18:05:04 PST 2033
Certificate fingerprints:
    MD5:  AE:9F:95:D0:A6:86:89:BC:A8:70:BA:34:FF:6B:AC:F9
    SHA1: BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:90:AF:A1:66:6E:44:5D:75
    Signature algorithm name: SHA1withRSA
    Version: 3

The line that begins with SHA1 contains the certificate's SHA-1 fingerprint. The fingerprint is the sequence of 20 two-digit hexadecimal numbers separated by colons.

Get an API key from the Google Developers Console

To get started with the Google Awareness API, click the Get a key button. It links to the Google Developers Console, which guides you through the process and activates the Awareness API automatically.

Get a key

Alternatively, follow these steps to get an API key:

  1. Go to the Google Developers Console.
  2. Select a project, or create a new one.
  3. Click Continue to enable the Awareness API.
  4. On the "Credentials" page, create an Android key and set the API credentials.

  5. In the 'Create key" dialog, you need to restrict your usage to Android apps. To do so, enter your app's SHA-1 fingerprint and package name, like in the following example:

    BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75
    
    com.example.android.awareness-example
    
  6. Click Create. Your new Android API key appears in the list of API keys for your project. An API key is a string of characters, like the following:

    AIzaSyBdVl-cTICSwYKrZ95LoVuw7dbMuDt1KG0
    

Now that you have an API key, you can add it to your app's manifest, as described in the Get started guide.

Activate Additional APIs

The Awareness API allows you to access multiple types of contextual data, such as beacons. To use these types, you need to enable the corresponding APIs in the Google Developers Console.

Service Awareness API methods API to enable
Beacons SnapshotApi.getBeaconState(), FenceApi.BeaconFence Nearby Messages API