The Android Developer Challenge is back! Submit your idea before December 2.

AppUpdateManager

public interface AppUpdateManager

com.google.android.play.core.appupdate.AppUpdateManager
Known Indirect Subclasses


Manages operations that allow your app to initiate its own updates.

For more information, read Support in-app updates.

Summary

Public methods

abstract Task<Void> completeUpdate()

For a flexible update flow, triggers the completion of the update.

abstract Task<AppUpdateInfo> getAppUpdateInfo()

Requests the update availability for the current app, an intent to start an update flow, and, if applicable, the state of updates currently in progress.

abstract void registerListener(InstallStateUpdatedListener listener)

Registers a listener for this app that receives state changes for self-update operations.

abstract boolean startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, int appUpdateType, IntentSenderForResultStarter starter, int requestCode)

Starts the desired update flow.

abstract boolean startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, int appUpdateType, Activity activity, int requestCode)

Starts the desired update flow.

abstract void unregisterListener(InstallStateUpdatedListener listener)

Unregisters a listener you previously registered using registerListener(InstallStateUpdatedListener).

Public methods

completeUpdate

Task<Void> completeUpdate ()

For a flexible update flow, triggers the completion of the update.

You should call this method to complete an update that has already been started via startUpdateFlowForResult(AppUpdateInfo, int, Activity, int) and is in the DOWNLOADED state.

Returns
Task<Void>

getAppUpdateInfo

Task<AppUpdateInfo> getAppUpdateInfo ()

Requests the update availability for the current app, an intent to start an update flow, and, if applicable, the state of updates currently in progress.

To learn more, read Check for update availability.

Returns
Task<AppUpdateInfo>

registerListener

void registerListener (InstallStateUpdatedListener listener)

Registers a listener for this app that receives state changes for self-update operations. Typically, you need to register a listener for only Flexible updates, and listeners should be unregistered using unregisterListener(InstallStateUpdatedListener) when you no longer need them.

To learn more, read Handle a flexible update.

Parameters
listener InstallStateUpdatedListener: The listener you want to register.

startUpdateFlowForResult

boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, 
                int appUpdateType, 
                IntentSenderForResultStarter starter, 
                int requestCode)

Starts the desired update flow.

This method should be called if you are starting the flow from a Component different from an Activity and you don't want to receive the onActivityResult call on the Activity.

For example, you can use it for androidx.fragment.app.Fragment:

startUpdateFlowForResult(info, type, fragment::startIntentSenderForResult, requestCode);
 

Starts a flow with type appUpdateType. Requires an AppUpdateInfo, which you can receive from getAppUpdateInfo(). This method can only start update flow types that are allowed according to isUpdateTypeAllowed(int).

Similar to startActivityForResult(Intent, int), this method is run "for result". The result from the flow's Activity can be handled by the onActivityResult of the object that would normally receive an activity result when the starter's startIntentSenderForResult is called. The result is tagged with the provided requestCode.

Each AppUpdateInfo instance can be used only in a single call to this method. If you need to call it multiple times - for instance, when retrying to start a flow in case of failure - you need to get a fresh AppUpdateInfo from getAppUpdateInfo().

For a list of possible result values and parameter documentation, see startUpdateFlowForResult(AppUpdateInfo, int, Activity, int).

Parameters
appUpdateInfo AppUpdateInfo

appUpdateType int

starter IntentSenderForResultStarter

requestCode int

Returns
boolean

Throws
IntentSender.SendIntentException

startUpdateFlowForResult

boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, 
                int appUpdateType, 
                Activity activity, 
                int requestCode)

Starts the desired update flow.

Starts a flow with type appUpdateType. Requires an AppUpdateInfo, which you can receive from getAppUpdateInfo(). This method can only start update flow types that are allowed according to isUpdateTypeAllowed(int).

Similar to startActivityForResult(Intent, int), this method is run "for result". The result from the flow's Activity can be handled by the provided activity's ERROR(/Activity#onActivityResult) and is tagged with the provided requestCode.

Each AppUpdateInfo instance can be used only in a single call to this method. If you need to call it multiple times - for instance, when retrying to start a flow in case of failure - you need to get a fresh AppUpdateInfo from getAppUpdateInfo().

In the flexible flow, the Activity returns right after user confirmation with one of the following values:

  • RESULT_OK: The user accepted the request to update.
  • RESULT_CANCELED: The user denied the request to update.
  • RESULT_IN_APP_UPDATE_FAILED: Something failed during the request for user confirmation. For example, the user terminates the app before responding to the request.

In the immediate flow, the Activity returns one of the following values:

  • RESULT_OK: The user accepted and the update succeeded (which, in practice, your app never should never receive because it already updated).
  • RESULT_CANCELED: The user denied or canceled the update.
  • RESULT_IN_APP_UPDATE_FAILED: The flow failed either during the user confirmation, the download, or the installation.

Parameters
appUpdateInfo AppUpdateInfo: An intent you use start an update. You get this using getAppUpdateInfo().

appUpdateType int: A value from AppUpdateType that determines the type of update flow.

activity Activity: the Activity that will be used for ERROR(/Activity#onActivityResult)

requestCode int: the request code that will be used for ERROR(/Activity#onActivityResult)

Returns
boolean Specifies whether the requested update has started.

Throws
IntentSender.SendIntentException If there is an error when starting the flow's Activity for result.

unregisterListener

void unregisterListener (InstallStateUpdatedListener listener)

Unregisters a listener you previously registered using registerListener(InstallStateUpdatedListener).

To learn more, read Handle a flexible update.

Parameters
listener InstallStateUpdatedListener: The listener you want to unregister.