Add the App Indexing API

The Android App Indexing API indexes user actions in your app, such as TYPE_VIEW. This lets your users see app pages they have visited as result in Search autocomplete. Users can view and delete past activity in apps at

The following steps describe how to integrate App Indexing API in your app. Use the Android Studio 2.x Code Generation utility to simplify your workflow.

Add Google Play services

dependencies {
  compile ''

Import classes


Add App Indexing API calls

Define the title, description, URL, and type for relevant activities and build the Action object. This enables search results to show your preferred app page title and description, and to serve richer results like play actions.

public class MainActivity extends Activity {
  private GoogleApiClient mClient;
  private Uri mUrl;
  private String mTitle;
  private String mDescription;

  protected void onCreate(Bundle savedInstanceState) {
    mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    mUrl = "";
    mTitle = "Standard Poodle";
    mDescription = "The Standard Poodle stands at least 18 inches at the withers";

  public Action getAction() {
    Thing object = new Thing.Builder()

    return new Action.Builder(Action.TYPE_VIEW)

Indicate the app activity

Call activity start after the view completely renders, passing in the App Indexing object defined above. Call the AppIndexApi.end() method after the activity completes, and disconnect your client.

  public void onStart() {
    AppIndex.AppIndexApi.start(mClient, getAction());

  public void onStop() {
    AppIndex.AppIndexApi.end(mClient, getAction());
Next: Test Your Implementation

Send feedback about...

Need help? Visit our support page.