Scroll to top

Get In Touch
Shah Industrial Estate, Veera Desai Road, Andheri West, Mumbai, Maharashtra 40005
[email protected]
Ph: +917303529920

Work Inquiries
[email protected]

Enable Personal Content Indexing

With personal content indexing, your app provides search results in the Google app for content tied to a user’s account. Users only see their own personal content on their devices in both search suggestions and personal results.

For example, if a user searches for “favorite chicken recipe,” the personal results tab includes the note they added to a chicken recipe in the recipe app.

If your app doesn’t include any personal content, you can skip this step and go straight to Log User Actions.

Before you start, make sure you support links to your app content and have added the App Indexing library to your app.

Establish the index and add objects

Create a class that extends the JobIntentService. The implementation outlined in this doc relies on the JobIntentService class to queue the updates to the on-device index, but you can use an alternative class to schedule the work. If you do follow the implementation using the JobIntentService class, make sure to also add the Android Support Library to your project’s build.gradle file.

Then, to include items in the app’s personal content index, create Indexable objects in the same class:

  • To create your indexable objects more conveniently, use existing builder classes whenever possible (for example, the MessageBuilder, DigitalDocumentBuilder, and PersonBuilder classes). See a list of common builder classes.
  • For content types that don’t have custom builders, use the generic Indexable.Builder() class.
  • Add more information through predefined data types and properties from Schema.org.

Result types

App Indexing lets you display your results in two ways:

  • Text-only: Google Search displays your indexed content as text results.
  • Slices: Google Search uses Slices, or UI templates from your app, to provide dynamic, interactive search results.

You can choose whichever result type best suits your app. Text-only results are less complicated to implement, but Slices provide a richer user experience.

Sample implementation

What should be in the personal content index?

Define Indexable objects for the following types of content:

  • User-specific content, like messages, photos, or documents.
  • Content that’s important to users, such as favorites or content that they may want to access more frequently. For example, documents or songs that they’ve bookmarked or marked for offline use.
  • Content generated in your app, not just accessed by it. For example, contacts that are created by users directly in your app, and stored by your app, not contacts from the phone’s directory.

Add a broadcast receiver to your app

Google Play Services periodically sends a request to your app to update its on-device index. This allows the on-device index to have the freshest content from your app. The BroadcastReceiver class receives this request and triggers the JobIntentService to process the indexing work. The example below uses the AppIndexingUpdateService class from the previous step.

Generate and refresh the index

Next, allow Google Play services to call the App Indexing service to update the on-device index with the user’s personal content in the following three situations:

  • When the app is installed on a device.
  • If an existing version of the app is updated to a version that supports personal content indexing.
  • Periodic calls over time to accurately reflect any changes that happen to the indexed content, ensuring a seamless user experience.

Additionally, if the on-device index is lost for any reason (e.g., if the index is corrupted), this call to update the index will repopulate it.

In your AndroidManifest.xml file, register the BroadcastReceiver so it can receive calls from Google Play Services to update the index. The example below uses the JobIntentService class to schedule the indexing updates:

<!-- Register the BroadcastReceiver -->
<receiver
    android:name=".AppIndexingUpdateReceiver"
    android:exported="true"
    android:permission="com.google.android.gms.permission.APPINDEXING">
    <intent-filter>
        <action android:name="com.google.firebase.appindexing.UPDATE_INDEX" />
    </intent-filter>
</receiver>

<!-- Grant the AppIndexingUpdateService permission and enable it to run after being triggered -->
<service
    android:name=".AppIndexingUpdateService"
    android:permission="android.permission.BIND_JOB_SERVICE" />

Update the index

When users add, update, or remove their personal content, the on-device index should reflect those changes. Add the following code to update content in the index:

Delete the index when users log out

Delete the on-device index when users log out of your app, on the logout event. Include the call to generate and refresh the index using AppIndexingService to repopulate the on-device index when users log in again.

To delete the on-device index when a user logs out of your app, add the following code to your app:

Post a comment

Your email address will not be published. Required fields are marked *

We use cookies to give you the best experience.