AppUpdateManager

public interface AppUpdateManager

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


Manages operations for self-updating an app.

Summary

Public methods

abstract Task<Void> completeUpdate()

Triggers the completion of the update of the app for the flexible flow.

abstract Task<AppUpdateInfo> getAppUpdateInfo()

Requests to retrieve the package updatability state, any available intent to start the update flow and the current state of updates in progress (if any).

abstract void registerListener(InstallStateUpdatedListener listener)

Registers a listener that will be alerted of state changes for self-update operations for this app.

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

Starts the desired update flow.

abstract void unregisterListener(InstallStateUpdatedListener listener)

Unregisters a listener previously added using registerListener(InstallStateUpdatedListener).

Public methods

completeUpdate

Task<Void> completeUpdate ()

Triggers the completion of the update of the app for the flexible flow.

This should be called to complete an update that has been started via startUpdateFlowForResult(AppUpdateInfo, int, Activity, int) and is in DOWNLOADED status.

Returns
Task<Void>

getAppUpdateInfo

Task<AppUpdateInfo> getAppUpdateInfo ()

Requests to retrieve the package updatability state, any available intent to start the update flow and the current state of updates in progress (if any).

Returns
Task<AppUpdateInfo>

registerListener

void registerListener (InstallStateUpdatedListener listener)

Registers a listener that will be alerted of state changes for self-update operations for this app. Listeners should be subsequently unregistered using unregisterListener(InstallStateUpdatedListener).

Parameters
listener InstallStateUpdatedListener

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).

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

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

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

  • RESULT_OK if the user accepted and the update succeeded (which in practice will never be received, because your app has been updated in the meantime)
  • RESULT_CANCELED if the user denied or canceled the update
  • RESULT_IN_APP_UPDATE_FAILED if the flow failed (either during the user confirmation, the download or the installation)

Parameters
appUpdateInfo AppUpdateInfo

appUpdateType int

activity Activity

requestCode int

Returns
boolean whether the flow is allowed and has been 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 previously added using registerListener(InstallStateUpdatedListener).

Parameters
listener InstallStateUpdatedListener