AppUpdateManager
public
interface
AppUpdateManager
com.google.android.play.core.appupdate.AppUpdateManager |
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
Task<Integer>
|
startUpdateFlow(AppUpdateInfo appUpdateInfo, Activity activity, AppUpdateOptions options)
Starts the desired update flow asynchronously. |
abstract
boolean
|
startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, ActivityResultLauncher<IntentSenderRequest> activityResultLauncher, AppUpdateOptions options)
Starts the desired update flow. |
abstract
boolean
|
startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, int appUpdateType, IntentSenderForResultStarter starter, int requestCode)
This method is deprecated.
This API has been deprecated in favor of startUpdateFlowForResult(AppUpdateInfo,
IntentSenderForResultStarter, AppUpdateOptions, int). Please use |
abstract
boolean
|
startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, Activity activity, AppUpdateOptions options, int requestCode)
Starts the desired update flow. |
abstract
boolean
|
startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, int appUpdateType, Activity activity, int requestCode)
This method is deprecated.
This API has been deprecated in favor of |
abstract
boolean
|
startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, IntentSenderForResultStarter starter, AppUpdateOptions options, int requestCode)
Starts the desired update flow. |
abstract
void
|
unregisterListener(InstallStateUpdatedListener listener)
Unregisters a listener you previously registered using |
Public methods
completeUpdate
public abstract 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, Activity, AppUpdateOptions, int)
and is in the InstallStatus.DOWNLOADED
state.
Returns | |
---|---|
Task<Void> |
getAppUpdateInfo
public 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.
To learn more, read Check for update availability.
Returns | |
---|---|
Task<AppUpdateInfo> |
registerListener
public abstract 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
|
startUpdateFlow
public abstract Task<Integer> startUpdateFlow (AppUpdateInfo appUpdateInfo, Activity activity, AppUpdateOptions options)
Starts the desired update flow asynchronously.
Starts a flow with provided options
. Requires an AppUpdateInfo
, which you
can receive from getAppUpdateInfo()
. This method can only start update flow types that
are allowed according to AppUpdateInfo.isUpdateTypeAllowed(AppUpdateOptions)
.
The result from the In-app update flow's Activity will be returned within the Task
.
If the update flow was displayed Task.isSuccessful()
you can check if the update was
successful using Task.getResult()
. The task is unsuccessful if you try to start the
update flow but AppUpdateInfo.isUpdateTypeAllowed(AppUpdateOptions)
is false.
This method is preferable to its synchronous counterparts relying on Activity#onActivityResult
if your app cannot change the onActivityResult() of its underlying
activity, e.g. for some game engines.
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 : an intent you use start an update. You get this using getAppUpdateInfo() . |
activity |
Activity : the Activity on whose Activity stack the update flow is run |
options |
AppUpdateOptions : the update options, including the type of flow |
Returns | |
---|---|
Task<Integer> |
a Task that completes once the dialog has been accepted, denied or closed
|
startUpdateFlowForResult
public abstract boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, ActivityResultLauncher<IntentSenderRequest> activityResultLauncher, AppUpdateOptions options)
Starts the desired update flow.
This API uses the ActivityResultLauncher provided by Jetpack components to launch the update flow for result.
Starts a flow with the provided options, including the flow type. Requires an AppUpdateInfo
, which you can receive from getAppUpdateInfo()
. This method can only
start update flow types that are allowed according to AppUpdateInfo.isUpdateTypeAllowed(AppUpdateOptions)
.
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, see startUpdateFlowForResult(AppUpdateInfo, Activity, AppUpdateOptions, int)
.
Parameters | |
---|---|
appUpdateInfo |
AppUpdateInfo : an intent you use to start an update. You get this using getAppUpdateInfo() . |
activityResultLauncher |
ActivityResultLauncher : An ActivityResultLauncher to launch the update flow. |
options |
AppUpdateOptions : the update options, including the type of flow. |
Returns | |
---|---|
boolean |
whether the requested update has started. |
startUpdateFlowForResult
public abstract boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, int appUpdateType, IntentSenderForResultStarter starter, int requestCode)
This method is deprecated.
This API has been deprecated in favor of startUpdateFlowForResult(AppUpdateInfo,
IntentSenderForResultStarter, AppUpdateOptions, int). Please use AppUpdateOptions
to specify AppUpdateType
.
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.
This is identical to calling startUpdateFlowForResult(AppUpdateInfo, IntentSenderForResultStarter, AppUpdateOptions, int)
, with the AppUpdateOptions.defaultOptions(int)
for the requested update flow. See its documentation for
further information.
For a list of possible result values and parameter documentation, see startUpdateFlowForResult(AppUpdateInfo, IntentSenderForResultStarter, AppUpdateOptions, int)
.
Parameters | |
---|---|
appUpdateInfo |
AppUpdateInfo |
appUpdateType |
int |
starter |
IntentSenderForResultStarter |
requestCode |
int |
Returns | |
---|---|
boolean |
Throws | |
---|---|
IntentSender.SendIntentException |
startUpdateFlowForResult
public abstract boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, Activity activity, AppUpdateOptions options, int requestCode)
Starts the desired update flow.
Starts a flow according to the provided options, which include the AppUpdateType
.
Requires an AppUpdateInfo
, which you can receive from getAppUpdateInfo()
.
This method can only start update flow types that are allowed according to AppUpdateInfo.isUpdateTypeAllowed(AppUpdateOptions)
.
Similar to Activity.startActivityForResult(Intent, int)
, this method is run "for result". The
result from the flow's Activity can be handled by the provided activity
's 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:
Activity.RESULT_OK
: The user accepted the request to update.Activity.RESULT_CANCELED
: The user denied the request to update.ActivityResult.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:
Activity.RESULT_OK
: The user accepted and the update succeeded (which, in practice, your app never should never receive because it already updated).Activity.RESULT_CANCELED
: The user denied or canceled the update.ActivityResult.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() . |
activity |
Activity : the Activity that will be used for Activity#onActivityResult |
options |
AppUpdateOptions : the update options, including the type of flow |
requestCode |
int : the request code that will be used for Activity#onActivityResult |
Returns | |
---|---|
boolean |
whether the requested update has started |
Throws | |
---|---|
IntentSender.SendIntentException |
if there is an error when starting the flow's Activity for result |
startUpdateFlowForResult
public abstract boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, int appUpdateType, Activity activity, int requestCode)
This method is deprecated.
This API has been deprecated in favor of startUpdateFlowForResult(AppUpdateInfo, Activity, AppUpdateOptions, int)
. Please use
AppUpdateOptions
to specify AppUpdateType
.
Starts the desired update flow.
Starts a flow of the provided AppUpdateType
.
This is identical to calling startUpdateFlowForResult(AppUpdateInfo, Activity, AppUpdateOptions, int)
, with the AppUpdateOptions.defaultOptions(int)
for the
requested update flow. See its documentation for further information.
For a list of possible result values and parameter documentation, see startUpdateFlowForResult(AppUpdateInfo, Activity, AppUpdateOptions, int)
.
Parameters | |
---|---|
appUpdateInfo |
AppUpdateInfo |
appUpdateType |
int |
activity |
Activity |
requestCode |
int |
Returns | |
---|---|
boolean |
Throws | |
---|---|
IntentSender.SendIntentException |
startUpdateFlowForResult
public abstract boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, IntentSenderForResultStarter starter, AppUpdateOptions options, 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 the provided options, including the flow type. Requires an AppUpdateInfo
, which you can receive from getAppUpdateInfo()
. This method can only
start update flow types that are allowed according to AppUpdateInfo.isUpdateTypeAllowed(AppUpdateOptions)
.
Similar to Activity.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, see startUpdateFlowForResult(AppUpdateInfo, Activity, AppUpdateOptions, int)
.
Parameters | |
---|---|
appUpdateInfo |
AppUpdateInfo : an intent you use start an update. You get this using getAppUpdateInfo() . |
starter |
IntentSenderForResultStarter : will be used for startIntentSenderForResult |
options |
AppUpdateOptions : the update options, including the type of flow |
requestCode |
int : the request code that will be used for Activity#onActivityResult |
Returns | |
---|---|
boolean |
whether the requested update has started |
Throws | |
---|---|
IntentSender.SendIntentException |
if there is an error when starting the flow's Activity for result |
unregisterListener
public abstract 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
|