Skip to content

Re-engage Users through Google Search with Firebase App Indexing (Android)

App Indexing is definitely one of the more heavily underrated features of Firebase. Perhaps, because people don’t know what it does.

Your app might be sitting quietly in a user’s app drawer, almost forgotten. Along the line, they might Google search for content your app delivers. When this happens, a card pointing to your app will be shown to the user to bring the user to your app directly to the activity and content your user is looking for, thanks to app indexing.

Image taken from the official site

So you guessed it. This is a re-engagement tool, ensuring your users get the most out of your app.

How does it work? If your site and your app have similar content, your app can take incoming links from the same search. Not only that, but the correct activity in your app will be launched directly based on how you define intent filters in your app.

Getting Started

implementation 'com.google.firebase:firebase-appindexing:16.0.2'

As with all things Firebase, start by adding the dependency to your app-level build.gradle file.

Upload assetlinks.json to your website

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

Upload a file like this to your website. The package name must obviously refer to your app. Note you’ll also need your app certificate for this.

Edit your Android Manifest

<activity
    android:label="@string/app_name"
    android:name=".client.RecipeActivity">


    <intent-filter
        android:autoVerify="true"
        android:label="@string/app_name">
        <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 "https://recipe-app.com/recipe" -->
        <data
            android:host="recipe-app.com"
            android:pathPrefix="/recipe"
            android:scheme="https" />
    </intent-filter>
</activity>

Add intent filters to your app where the data host points to your site and the pathPrefix points to a particular link in your site. This will allow the specified link to bring the user directly to the activity where the intent filter is contained in.

Note the autoVerify attribute. Upon installation of your app, due to autoVerify’s presence, the system will attempt to verify all hosts associated in those intent filters, therefore making your app into the default handler for those links.

Conclusion

Short as this was, it doesn’t take much to get App Indexing running well in your app. It’s a very useful tool to have to keep your users well engaged with your app, especially if your app’s been left sitting quietly in the app drawer.

This time, on top of the official docs, the examples here were taken from this video on the Firebase YouTube channel. Their videos there are amazing and definitely worth checking out.