UserActions

  • UserActions provides methods for logging user actions within an app.

  • Direct use of theplay-services-appindex SDK is not supported; use the Google Shortcuts Integration Library instead.

  • Android shortcuts offer quick ways for users to perform actions or access content.

  • Thestart(Action) method logs the beginning of a user action of some duration.

  • Theend(Action) method logs the completion of a user action, including instantaneous ones.

public abstract classUserActions extendsObject
Direct use of play-services-appindex SDK is not supported. You should use theGoogle Shortcuts Integration Library to donate dynamic shortcuts to Google Assistant.Android shortcuts provide users with quick methods to perform an action or access content in an app. For more information, see the full documentation onpushing dynamic shortcuts to Assistant.

Provides methods for logging actions that the user takes in the app.

This is a simple example for logging that the user has started to view an article:

UserActions.getInstance(getApplicationContext()).start(   Actions.newView(     "Index your app with Google App Index",     "//example.net/articles/02101984.html"));

Constant Summary

String APP_INDEXING_API_TAGThe tag used for logging debug information for calls toUserActions class.

Public Constructor Summary

Public Method Summary

abstract Task<Void>
end(Action action)
Logs that the user has stopped doing something in the app.
synchronized staticUserActions
getInstance(Context context)
Returns an instance ofUserActions.
abstract Task<Void>
start(Action action)
Logs that the user has started doing something in the app.

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 finalStringAPP_INDEXING_API_TAG

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

To enable logging:
adb shell setproplog.tag.UserActionsDEBUG

Constant Value:"UserActions"

Public Constructors

publicUserActions()

Public Methods

public abstract Task<Void>end(Action action)

Logs that the user has stopped doing something in the app.

Use this method for a user action of some duration that has come to an end, like when the user has finished viewing an article or stopped listening to a song, as well as for instantaneous actions the user has taken, such as sending a message or adding a song to a playlist. For these instantaneous actions, don't call start(Action) at all, but just end(Action).

Parameters
actionTheAction describing either the instantaneous action the user has just taken, or the more long-lived activity the user has stopped doing in the app; for the latter start(Action) should be called before calling end(Action).
Returns
  • ATask indicating the result of the operation.

public static synchronizedUserActionsgetInstance(Context context)

Returns an instance ofUserActions.

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

public abstract Task<Void>start(Action action)

Logs that the user has started doing something in the app.

Use this method for a user action of some duration, like viewing an article, or listening to a song. If the action is instantaneous, such as sending a message or adding a song to a playlist, then make a single call to end(Action) instead.

Parameters
actionTheAction describing what the user has started doing in the app.
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 2024-10-31 UTC.