FirebaseAppIndex

public abstract classFirebaseAppIndex extendsObject

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

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

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

The unique identifier for anIndexable is the URL. This means that there cannot be multiple differentIndexables with the same URL, but you can call update(Indexable...) multiple times to update the sameIndexable 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).

The static accessors and object methods of FirebaseAppIndex are thread-safe. However, Indexables are not. Therefore, you should not insert, update, or remove the same Indexable from different threads.

Constant Summary

String ACTION_UPDATE_INDEXThe intent action that will be used by the indexing service to request an app to update all itsIndexables.
String APP_INDEXING_API_TAGThe tag used for logging debug information for calls toFirebaseAppIndex class.
String EXTRA_UPDATE_INDEX_REASONUsed as an int extra field in ACTION_UPDATE_INDEX intent to indicate the reason for the update request.
int EXTRA_UPDATE_INDEX_REASON_REBUILDAn 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_REFRESHAn 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 Constructor Summary

Public Method Summary

synchronized staticFirebaseAppIndex
getInstance(Context context)
Returns an instance ofFirebaseAppIndex.
abstract Task<Void>
remove(String... urls)
Removes one or multipleIndexables from the index.
abstract Task<Void>
removeAll()
Removes all data from the index.
abstract Task<Void>
update(Indexable... indexables)
Inserts or updates one or multipleIndexables in the index.

Inherited Method Summary

From class java.lang.Object
Object
clone()
boolean
equals(Object arg0)
void
finalize()
finalClass<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()

Constants

public static finalStringACTION_UPDATE_INDEX

The intent action that will be used by the indexing service to request an app to update all itsIndexables. 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:

 <receiver android:name=".MyIndexingReceiver"     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>
The receiver needs to schedule the indexing work to happen asynchronously in the background.An example implementation is documented in the developer guide.
Constant Value:"com.google.firebase.appindexing.UPDATE_INDEX"

public static finalStringAPP_INDEXING_API_TAG

The tag used for logging debug information for calls toFirebaseAppIndex class.

To enable logging:
adb shell setproplog.tag.FirebaseAppIndexDEBUG

Constant Value:"FirebaseAppIndex"

public static finalStringEXTRA_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 intEXTRA_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

public static final intEXTRA_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

Public Constructors

publicFirebaseAppIndex()

Public Methods

public static synchronizedFirebaseAppIndexgetInstance(Context context)

Returns an instance ofFirebaseAppIndex.

This method does not require FirebaseApp initialization. Instead, the application context is inferred from thecontext that is explicitly passed in.

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

Removes one or multipleIndexables from the index.

Parameters
urlsOne or multiple URLs of theIndexables to be removed from the index. The total number of URLs that can be passed in a single call is limited toIndexable.MAX_INDEXABLES_TO_BE_UPDATED_IN_ONE_CALL.
Returns
  • ATask indicating the result of the operation

public abstract Task<Void>removeAll()

Removes all data from the index.

Returns
  • ATask indicating the result of the operation.

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

Inserts or updates one or multipleIndexables in the index. TheIndexables are identified by their URL, and the update is a complete replacement (all previously indexed information for a givenIndexable is replaced with the new one).

Parameters
indexablesOne or multipleIndexables to be inserted or updated in the index. The total number ofIndexables that can be passed in a single call is limited toIndexable.MAX_INDEXABLES_TO_BE_UPDATED_IN_ONE_CALL).
Returns
  • ATask indicating the result of the operation.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2021-05-11 UTC.