public abstract class

FirebaseAppIndex

extends Object
java.lang.Object
   ↳ com.google.firebase.appindexing.FirebaseAppIndex

Class Overview

Provides methods for managing the index, by inserting, updating and removing Indexables in the app.

This is a simple example for inserting a user's recipe into the index:

 Indexable recipe = new Indexable.Builder()
     .setName("My new brownie recipe")
     .setUrl("http://example.net/recipes/02101984")
     .build();
 FirebaseAppIndex.getInstance().update(recipe);
 
 

The unique identifier for an Indexable is the URL. This means that there cannot be multiple different Indexables with the same URL, but you can call update(Indexable...) multiple times to update the same Indexable as it changes over time.

The app should handle the ACTION_UPDATE_INDEX intent so that Google Play services can update the on-device index in the following situations:

  • When the app is installed on a device.
  • If an existing version of the app is updated to a version that supports the intent.
  • Periodic calls over time to accurately refresh the index.
  • If the on-device index is lost for any reason (e.g., if the index is corrupted).

Summary

Constants
String ACTION_UPDATE_INDEX The intent action that will be used by the indexing service to request an app to update all its Indexables.
String APP_INDEXING_API_TAG The tag used for logging debug information for calls to FirebaseAppIndex class.
String EXTRA_UPDATE_INDEX_REASON Used as an int extra field in ACTION_UPDATE_INDEX intent to indicate the reason for the update request.
int EXTRA_UPDATE_INDEX_REASON_REBUILD An int value for EXTRA_UPDATE_INDEX_REASON when the update request is sent because the index needs to be fully rebuilt.
int EXTRA_UPDATE_INDEX_REASON_REFRESH An int value for EXTRA_UPDATE_INDEX_REASON when the update request is sent because some content has not been re-indexed in some time (>30 days), and needs to be re-indexed to stay in the index.
Public Constructors
FirebaseAppIndex()
Public Methods
static FirebaseAppIndex getInstance()
Returns an instance of FirebaseAppIndex.
abstract Task<Void> remove(String... urls)
Removes one or multiple Indexables from the index.
abstract Task<Void> removeAll()
Removes all data from the index.
abstract Task<Void> update(Indexable... indexables)
Inserts or updates one or multiple Indexables in the index.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_UPDATE_INDEX

The intent action that will be used by the indexing service to request an app to update all its Indexables. When specifying the intent in the Manifest file you can also define a permission so that Google Play services is the only app allowed to trigger the intent.
Example entry for the Manifest file:

 <service android:name=".MyIndexingService"
     android:exported="true"
     android:permission="com.google.android.gms.permission.APPINDEXING">
     <intent-filter>
         <action android:name="com.google.firebase.appindexing.UPDATE_INDEX"/>
     </intent-filter>
 </service>
 
 

Constant Value: "com.google.firebase.appindexing.UPDATE_INDEX"

public static final String APP_INDEXING_API_TAG

The tag used for logging debug information for calls to FirebaseAppIndex class.

To enable logging:
adb shell setprop log.tag.FirebaseAppIndex DEBUG

Constant Value: "FirebaseAppIndex"

public static final String EXTRA_UPDATE_INDEX_REASON

Used as an int extra field in ACTION_UPDATE_INDEX intent to indicate the reason for the update request. Possible values are EXTRA_UPDATE_INDEX_REASON_REBUILD and EXTRA_UPDATE_INDEX_REASON_REFRESH.

Constant Value: "com.google.firebase.appindexing.extra.REASON"

public static final int EXTRA_UPDATE_INDEX_REASON_REBUILD

An int value for EXTRA_UPDATE_INDEX_REASON when the update request is sent because the index needs to be fully rebuilt. This could be for several reasons, including app installation (the app is newly installed on the device) or index resets (for example because of temporary storage constraints).

Constant Value: 1 (0x00000001)

public static final int EXTRA_UPDATE_INDEX_REASON_REFRESH

An int value for EXTRA_UPDATE_INDEX_REASON when the update request is sent because some content has not been re-indexed in some time (>30 days), and needs to be re-indexed to stay in the index.

Constant Value: 2 (0x00000002)

Public Constructors

public FirebaseAppIndex ()

Public Methods

public static FirebaseAppIndex getInstance ()

Returns an instance of FirebaseAppIndex.

The default FirebaseApp instance must have been initialized before this function is called.

Returns
FirebaseAppIndex

public abstract Task<Void> remove (String... urls)

Removes one or multiple Indexables from the index.

Parameters
urls String: One or multiple URLs of the Indexables to be removed from the index. The total number of URLs that can be passed in a single call is limited to Indexable.MAX_INDEXABLES_TO_BE_UPDATED_IN_ONE_CALL.
Returns
Task<Void> A Task indicating the result of the operation

public abstract Task<Void> removeAll ()

Removes all data from the index.

Returns
Task<Void> A Task indicating the result of the operation.

public abstract Task<Void> update (Indexable... indexables)

Inserts or updates one or multiple Indexables in the index. The Indexables are identified by their URL, and the update is a complete replacement (all previously indexed information for a given Indexable is replaced with the new one).

Parameters
indexables Indexable: One or multiple Indexables to be inserted or updated in the index. The total number of Indexables that can be passed in a single call is limited to Indexable.MAX_INDEXABLES_TO_BE_UPDATED_IN_ONE_CALL).
Returns
Task<Void> A Task indicating the result of the operation.