Enable Content Indexing

To create a seamless experience for users who find your app's content in public Google Search results or in on-device In Apps search, add link associations and handling to your app. The steps in this article help you make sure users land in the right place when they open a link to your app. Users who don't have your app installed can run your app without installing it through Android Instant Apps.

Associate your site and your app

Associate your site with your app using Digital Asset Links and build your app against API level 23 or higher for the Android platform.

Digital Asset Links take the form of a JSON file called assetlinks.json in your web server's .well-known directory. Configure the following fields in your assetlinks.json file:

  • Relation: To grant link-opening permissions to the Android app you specify in the target, use delegate_permission/common.handle_all_urls.
  • Target: Use the package name and the SHA-256 fingerprint of the certificate you normally use to sign your Android app for deployment to the Play Store. To learn more about deployment and your signing certificate, see Signing Your Applications.

Here’s an example assetlinks.json file for an app package named com.recipe_app. Change the package name and sha256_cert_fingerprints content to match those for your app.

  [{
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target" : { "namespace": "android_app",
      "package_name": "com.recipe_app",
                 "sha256_cert_fingerprints": ["hash_of_app_certificate"] }
  }]

Upload your assetlinks.json file and make sure the read access is set as visible to everyone at https://<yoursite>/.well-known/assetlinks.json.

Route incoming links

The first step in handling incoming links is to add intent filters to your Android manifest file. Intent filters indicate the view your app opens to when a user clicks a link from Google Search results. It's important that the intent filter is consistent with your app's structure, so that incoming links open on the right view. If the intent filter you add in this step claims to support a URL, your app must also include logic to correctly handle the incoming link (as discussed in the next step).

  1. Open your app in Android Studio.
  2. In the Android view of the Project window, double-click the AndroidManifest.xml file to open it in the Code Editor.
  3. Add the intent filter using one of the following three methods:
    • In an <activity> element, click in the left column so the light bulb appears. Click and select Add URL.
    • Right-click in an <activity> element and select Generate > URL.
    • Place your cursor in an activity, and then select Code > Generate > URL.
    • The activity expands to show the updated URL details:
       <activity
          android:name=".client.RecipeActivity"
          android:label="@string/app_name"
          android:exported="true"
          android:launchMode="singleTop"
          android:theme="@android:style/Theme.Holo.NoActionBar">
          <intent-filter android:label="@string/app_name" android:autoVerify="true">
              <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.DEFAULT" />
              <category android:name="android.intent.category.BROWSABLE" />
              <!-- Accepts URIs that begin with "http://recipe-app.com/recipe" -->
              <data android:scheme="http"
                  android:host="recipe-app.com"
                  android:pathPrefix="/recipe" />
          </intent-filter>
      </activity>
      
       
  4. Check that the host field is correct, since it defaults to the app package name as declared in the <manifest> tag. The DEFAULT and BROWSABLE categories are required. You must also specify android:autoVerify="true". Lastly, you may also want to edit the pathPrefix and the scheme properties.

    Here’s an example where the manifest has been updated for the recipe-app.com site. It handles the pathPrefix property, and both HTTP and HTTPS schemes by adding a second <data> tag.

      <activity
        android:name=".client.RecipeActivity"
        android:label="@string/app_name"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@android:style/Theme.Holo.NoActionBar">
        <intent-filter android:label="@string/app_name" android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- Accepts URIs that begin with "http://recipe-app.com/recipe" -->
            <data android:scheme="http"
                android:host="recipe-app.com"
                android:pathPrefix="/recipe" />
            <!-- Accepts URIs that begin with "https://recipe-app.com/recipe" -->
            <data android:scheme="https"
                android:host="recipe-app.com"
                android:pathPrefix="/recipe" />
        </intent-filter>
    </activity>
    

Handle incoming URLs

Now that you've set the intent filters in your Android Manifest, your app launches specific activities based on the URLs passed to it. For example, the RecipeActivity activity launches in response to a URL matching http://recipe-app.com/recipe/*, like http://recipe-app.com/recipe/wedge-salad.

In this Activity, you can then call the getIntent() method for the details from this intent. So your onCreate code could look like this:

  @Override
  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_recipe);
     onNewIntent(getIntent());
  }

The onCreate() method passes the results of the getIntent() method (an Intent) to onNewIntent. The getDataString() method surfaces the URL and makes it relatively simple to parse. For example, suppose you want your app to display a specific recipe by its recipe ID. To parse out the last element of the URL (the recipe ID), use code like this:

  protected void onNewIntent(Intent intent) {
    String action = intent.getAction();
    String data = intent.getDataString();
    if (Intent.ACTION_VIEW.equals(action) && data != null) {
        String recipeId = data.substring(data.lastIndexOf("/") + 1);
        Uri contentUri = Uri.parse("content://com.recipe_app/recipe/").buildUpon()
                .appendPath(recipeId).build();
        showRecipe(contentUri);
    }
}
  

Learn more about Handling App Links in the Android Developer documentation.

Refine indexing (optional)

If your public app content includes elements you don’t want to include in Google Search results, you can make the following adjustments:

  • Exclude specific pages from Search results: To specify the URLs you want to exclude from Google Search results, create a noindex.xml file. This is similar to how the robots noindex meta tag works for websites.
  • Exclude real-time app notifications from Search results: Add a specific exclude tag for app notifications to the noindex.xml file.

Learn how to implement these exclusions in Refine Indexing with noindex.xml.

Next: Enable Personal Content Indexing

Send feedback about...

Need help? Visit our support page.