Added in API level 21

PackageInstaller

open class PackageInstaller
kotlin.Any
   ↳ android.content.pm.PackageInstaller

Offers the ability to install, upgrade, and remove applications on the device. This includes support for apps packaged either as a single "monolithic" APK, or apps packaged as multiple "split" APKs.

An app is delivered for installation through a PackageInstaller.Session, which any app can create. Once the session is created, the installer can stream one or more APKs into place until it decides to either commit or destroy the session. Committing may require user intervention to complete the installation, unless the caller falls into one of the following categories, in which case the installation will complete automatically.

  • the device owner
  • the affiliated profile owner

Sessions can install brand new apps, upgrade existing apps, or add new splits into an existing app.

Apps packaged as multiple split APKs always consist of a single "base" APK (with a null split name) and zero or more "split" APKs (with unique split names). Any subset of these APKs can be installed together, as long as the following constraints are met:

  • All APKs must have the exact same package name, version code, and signing certificates.
  • All APKs must have unique split names.
  • All installations must contain a single base APK.

The ApiDemos project contains examples of using this API: ApiDemos/src/com/example/android/apis/content/InstallApk*.java.

Summary

Nested classes

A class to encapsulate constraints for installation.

The callback result of checkInstallConstraints(java.util.List,android.content.pm.PackageInstaller.InstallConstraints,java.util.concurrent.Executor,java.util.function.Consumer).

Details for requesting the pre-commit install approval.

open

An installation that is being actively staged.

abstract

Events for observing session lifecycle.

open

Details for an active install session.

open

Parameters for creating a new PackageInstaller.Session.

Constants
static String

Broadcast Action: Explicit broadcast sent to the last known default launcher when a session for a new install is committed.

static String

Activity Action: Show details about a particular install session.

static String

Broadcast Action: Send information about a staged install session when its state is updated.

static String

The InstallConstraints object.

static String

The InstallConstraintsResult object.

static String

Another package name relevant to a status.

static String

Package name that an operation is working with.

static String

Indicate if the status is for a pre-approval request.

static String

SessionInfo that an operation is working with.

static String

An integer session ID that an operation is working with.

static String

Current status of an operation.

static String

Detailed string representation of the status, including raw details that are useful for debugging.

static String

Storage path relevant to a status.

static Int

Code indicating that the package being installed comes from a file that was downloaded to the device by the user.

static Int

Code indicating that the package being installed comes from a local file on the device.

static Int

Code indicating that the package being installed is from a source not reflected by any other package source constant.

static Int

Code indicating that the package being installed is from a store.

static Int

The installer did not call PackageInstaller.SessionParams#setPackageSource(int) to specify the package source.

static Int

The operation failed in a generic way.

static Int

The operation failed because it was actively aborted.

static Int

The operation failed because it was blocked.

static Int

The operation failed because it conflicts (or is inconsistent with) with another package already installed on the device.

static Int

The operation failed because it is fundamentally incompatible with this device.

static Int

The operation failed because one or more of the APKs was invalid.

static Int

The operation failed because of storage issues.

static Int

The operation failed because it didn't complete within the specified timeout.

static Int

User action is currently required to proceed.

static Int

The operation succeeded.

Public methods
open Unit
abandonSession(sessionId: Int)

Completely abandon the given session, destroying all staged data and rendering it invalid.

open Unit

Check if install constraints are satisfied for the given packages.

open Unit
commitSessionAfterInstallConstraintsAreMet(sessionId: Int, statusReceiver: IntentSender, constraints: PackageInstaller.InstallConstraints, timeoutMillis: Long)

Commit the session when all constraints are satisfied.

open Int

Create a new session using the given parameters, returning a unique ID that represents the session.

open PackageInstaller.SessionInfo?

Returns first active staged session, or null if there is none.

open MutableList<PackageInstaller.SessionInfo!>

Returns list of active staged sessions.

open MutableList<PackageInstaller.SessionInfo!>

Return list of all known install sessions, regardless of the installer.

open MutableList<PackageInstaller.SessionInfo!>

Return list of all known install sessions owned by the calling app.

open PackageInstaller.SessionInfo?
getSessionInfo(sessionId: Int)

Return details for a specific session.

open MutableList<PackageInstaller.SessionInfo!>

Return list of all staged install sessions.

open Unit
installExistingPackage(packageName: String, installReason: Int, statusReceiver: IntentSender?)

Install the given package, which already exists on the device, for the user for which this installer was created.

open PackageInstaller.Session
openSession(sessionId: Int)

Open an existing session to actively perform work.

open Unit

Register to watch for session lifecycle events.

open Unit

Register to watch for session lifecycle events.

open Unit
uninstall(packageName: String, statusReceiver: IntentSender)

Uninstall the given package, removing it completely from the device.

open Unit
uninstall(versionedPackage: VersionedPackage, statusReceiver: IntentSender)

Uninstall the given package with a specific version code, removing it completely from the device.

open Unit
uninstall(versionedPackage: VersionedPackage, flags: Int, statusReceiver: IntentSender)

Uninstall the given package with a specific version code, removing it completely from the device.

open Unit
uninstallExistingPackage(packageName: String, statusReceiver: IntentSender?)

Uninstall the given package for the user for which this installer was created if the package will still exist for other users on the device.

open Unit

Unregister a previously registered callback.

open Unit
updateSessionAppIcon(sessionId: Int, appIcon: Bitmap?)

Update the icon representing the app being installed in a specific session.

open Unit
updateSessionAppLabel(sessionId: Int, appLabel: CharSequence?)

Update the label representing the app being installed in a specific session.

open Unit
waitForInstallConstraints(packageNames: MutableList<String!>, constraints: PackageInstaller.InstallConstraints, callback: IntentSender, timeoutMillis: Long)

Similar to checkInstallConstraints(java.util.List,android.content.pm.PackageInstaller.InstallConstraints,java.util.concurrent.Executor,java.util.function.Consumer), but the callback is invoked only when the constraints are satisfied or after timeout.

Constants

ACTION_SESSION_COMMITTED

Added in API level 26
static val ACTION_SESSION_COMMITTED: String

Broadcast Action: Explicit broadcast sent to the last known default launcher when a session for a new install is committed. For managed profile, this is sent to the default launcher of the primary profile.

The associated session is defined in EXTRA_SESSION and the user for which this session was created in Intent#EXTRA_USER.

Value: "android.content.pm.action.SESSION_COMMITTED"

ACTION_SESSION_DETAILS

Added in API level 21
static val ACTION_SESSION_DETAILS: String

Activity Action: Show details about a particular install session. This may surface actions such as pause, resume, or cancel.

This should always be scoped to the installer package that owns the session. Clients should use SessionInfo#createDetailsIntent() to build this intent correctly.

In some cases, a matching Activity may not exist, so ensure you safeguard against this.

The session to show details for is defined in EXTRA_SESSION_ID.

Value: "android.content.pm.action.SESSION_DETAILS"

ACTION_SESSION_UPDATED

Added in API level 29
static val ACTION_SESSION_UPDATED: String

Broadcast Action: Send information about a staged install session when its state is updated.

The associated session information is defined in EXTRA_SESSION.

Value: "android.content.pm.action.SESSION_UPDATED"

EXTRA_INSTALL_CONSTRAINTS

Added in API level 34
static val EXTRA_INSTALL_CONSTRAINTS: String

The InstallConstraints object.

Value: "android.content.pm.extra.INSTALL_CONSTRAINTS"

EXTRA_INSTALL_CONSTRAINTS_RESULT

Added in API level 34
static val EXTRA_INSTALL_CONSTRAINTS_RESULT: String

The InstallConstraintsResult object.

Value: "android.content.pm.extra.INSTALL_CONSTRAINTS_RESULT"

EXTRA_OTHER_PACKAGE_NAME

Added in API level 21
static val EXTRA_OTHER_PACKAGE_NAME: String

Another package name relevant to a status. This is typically the package responsible for causing an operation failure.

Value: "android.content.pm.extra.OTHER_PACKAGE_NAME"

EXTRA_PACKAGE_NAME

Added in API level 21
static val EXTRA_PACKAGE_NAME: String

Package name that an operation is working with.

Value: "android.content.pm.extra.PACKAGE_NAME"

EXTRA_PRE_APPROVAL

Added in API level 34
static val EXTRA_PRE_APPROVAL: String

Indicate if the status is for a pre-approval request. If callers use the same IntentSender for both Session#requestUserPreapproval(PreapprovalDetails, IntentSender) and Session#commit(IntentSender), they can use this to differentiate between them.

Value: "android.content.pm.extra.PRE_APPROVAL"

EXTRA_SESSION

Added in API level 26
static val EXTRA_SESSION: String

SessionInfo that an operation is working with.

Value: "android.content.pm.extra.SESSION"

EXTRA_SESSION_ID

Added in API level 21
static val EXTRA_SESSION_ID: String

An integer session ID that an operation is working with.

Value: "android.content.pm.extra.SESSION_ID"

EXTRA_STATUS

Added in API level 21
static val EXTRA_STATUS: String

Current status of an operation. Will be one of STATUS_PENDING_USER_ACTION, STATUS_SUCCESS, STATUS_FAILURE, STATUS_FAILURE_ABORTED, STATUS_FAILURE_BLOCKED, STATUS_FAILURE_CONFLICT, STATUS_FAILURE_INCOMPATIBLE, STATUS_FAILURE_INVALID, STATUS_FAILURE_STORAGE, or STATUS_FAILURE_TIMEOUT.

More information about a status may be available through additional extras; see the individual status documentation for details.

Value: "android.content.pm.extra.STATUS"

EXTRA_STATUS_MESSAGE

Added in API level 21
static val EXTRA_STATUS_MESSAGE: String

Detailed string representation of the status, including raw details that are useful for debugging.

Value: "android.content.pm.extra.STATUS_MESSAGE"

EXTRA_STORAGE_PATH

Added in API level 21
static val EXTRA_STORAGE_PATH: String

Storage path relevant to a status.

Value: "android.content.pm.extra.STORAGE_PATH"

PACKAGE_SOURCE_DOWNLOADED_FILE

Added in API level 33
static val PACKAGE_SOURCE_DOWNLOADED_FILE: Int

Code indicating that the package being installed comes from a file that was downloaded to the device by the user. For use in place of PACKAGE_SOURCE_LOCAL_FILE when the installer knows the package was downloaded.

Value: 4

PACKAGE_SOURCE_LOCAL_FILE

Added in API level 33
static val PACKAGE_SOURCE_LOCAL_FILE: Int

Code indicating that the package being installed comes from a local file on the device. A file manager that is facilitating the installation of an APK file would use this.

Value: 3

PACKAGE_SOURCE_OTHER

Added in API level 33
static val PACKAGE_SOURCE_OTHER: Int

Code indicating that the package being installed is from a source not reflected by any other package source constant.

Value: 1

PACKAGE_SOURCE_STORE

Added in API level 33
static val PACKAGE_SOURCE_STORE: Int

Code indicating that the package being installed is from a store. An app store that installs an app for the user would use this.

Value: 2

PACKAGE_SOURCE_UNSPECIFIED

Added in API level 33
static val PACKAGE_SOURCE_UNSPECIFIED: Int

The installer did not call PackageInstaller.SessionParams#setPackageSource(int) to specify the package source.

Value: 0

STATUS_FAILURE

Added in API level 21
static val STATUS_FAILURE: Int

The operation failed in a generic way. The system will always try to provide a more specific failure reason, but in some rare cases this may be delivered.

Value: 1

STATUS_FAILURE_ABORTED

Added in API level 21
static val STATUS_FAILURE_ABORTED: Int

The operation failed because it was actively aborted. For example, the user actively declined requested permissions, or the session was abandoned.

Value: 3

STATUS_FAILURE_BLOCKED

Added in API level 21
static val STATUS_FAILURE_BLOCKED: Int

The operation failed because it was blocked. For example, a device policy may be blocking the operation, a package verifier may have blocked the operation, or the app may be required for core system operation.

The result may also contain EXTRA_OTHER_PACKAGE_NAME with the specific package blocking the install.

Value: 2

STATUS_FAILURE_CONFLICT

Added in API level 21
static val STATUS_FAILURE_CONFLICT: Int

The operation failed because it conflicts (or is inconsistent with) with another package already installed on the device. For example, an existing permission, incompatible certificates, etc. The user may be able to uninstall another app to fix the issue.

The result may also contain EXTRA_OTHER_PACKAGE_NAME with the specific package identified as the cause of the conflict.

Value: 5

STATUS_FAILURE_INCOMPATIBLE

Added in API level 21
static val STATUS_FAILURE_INCOMPATIBLE: Int

The operation failed because it is fundamentally incompatible with this device. For example, the app may require a hardware feature that doesn't exist, it may be missing native code for the ABIs supported by the device, or it requires a newer SDK version, etc. Starting in Build.VERSION_CODES#UPSIDE_DOWN_CAKE, an app with only 32-bit native code can still be installed on a device that supports both 64-bit and 32-bit ABIs. However, a warning dialog will be displayed when the app is launched.

Value: 7

STATUS_FAILURE_INVALID

Added in API level 21
static val STATUS_FAILURE_INVALID: Int

The operation failed because one or more of the APKs was invalid. For example, they might be malformed, corrupt, incorrectly signed, mismatched, etc.

Value: 4

STATUS_FAILURE_STORAGE

Added in API level 21
static val STATUS_FAILURE_STORAGE: Int

The operation failed because of storage issues. For example, the device may be running low on space, or external media may be unavailable. The user may be able to help free space or insert different external media.

The result may also contain EXTRA_STORAGE_PATH with the path to the storage device that caused the failure.

Value: 6

STATUS_FAILURE_TIMEOUT

Added in API level 34
static val STATUS_FAILURE_TIMEOUT: Int

The operation failed because it didn't complete within the specified timeout.

Value: 8

STATUS_PENDING_USER_ACTION

Added in API level 21
static val STATUS_PENDING_USER_ACTION: Int

User action is currently required to proceed. You can launch the intent activity described by Intent#EXTRA_INTENT to involve the user and continue.

You may choose to immediately launch the intent if the user is actively using your app. Otherwise, you should use a notification to guide the user back into your app before launching.

Value: -1

STATUS_SUCCESS

Added in API level 21
static val STATUS_SUCCESS: Int

The operation succeeded.

Value: 0

Public methods

abandonSession

Added in API level 21
open fun abandonSession(sessionId: Int): Unit

Completely abandon the given session, destroying all staged data and rendering it invalid. Abandoned sessions will be reported to SessionCallback listeners as failures. This is equivalent to opening the session and calling Session#abandon().

Exceptions
java.lang.SecurityException when the caller does not own the session, or the session is invalid.

checkInstallConstraints

Added in API level 34
open fun checkInstallConstraints(
    packageNames: MutableList<String!>,
    constraints: PackageInstaller.InstallConstraints,
    executor: Executor,
    callback: Consumer<PackageInstaller.InstallConstraintsResult!>
): Unit

Check if install constraints are satisfied for the given packages. Note this query result is just a hint and subject to race because system states could change anytime in-between this query and committing the session. The result is returned by a callback because some constraints might take a long time to evaluate.

Parameters
packageNames MutableList<String!>: a list of package names to check the constraints for installation This value cannot be null.
constraints PackageInstaller.InstallConstraints: the constraints for installation. This value cannot be null.
executor Executor: the Executor on which to invoke the callback This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback Consumer<PackageInstaller.InstallConstraintsResult!>: called when the InstallConstraintsResult is ready This value cannot be null.
Exceptions
java.lang.SecurityException if the given packages' installer of record doesn't match the caller's own package name or the installerPackageName set by the caller doesn't match the caller's own package name.

commitSessionAfterInstallConstraintsAreMet

Added in API level 34
open fun commitSessionAfterInstallConstraintsAreMet(
    sessionId: Int,
    statusReceiver: IntentSender,
    constraints: PackageInstaller.InstallConstraints,
    timeoutMillis: Long
): Unit

Commit the session when all constraints are satisfied. This is a convenient method to combine waitForInstallConstraints(java.util.List,android.content.pm.PackageInstaller.InstallConstraints,android.content.IntentSender,long) and Session#commit(IntentSender).

Once this method is called, the session is sealed and no additional mutations may be performed on the session. In the case of timeout, you may commit the session again using this method or Session#commit(IntentSender) for retries.

Parameters
sessionId Int: the session ID to commit when all constraints are satisfied.
statusReceiver IntentSender: Called when the state of the session changes. Intents sent to this receiver contain EXTRA_STATUS. Refer to the individual status codes on how to handle them. This value cannot be null.
constraints PackageInstaller.InstallConstraints: The requirements to satisfy before committing the session. This value cannot be null.
timeoutMillis Long: The maximum time to wait, in milliseconds until the constraints are satisfied. The caller will be notified via statusReceiver if timeout happens before commit. Value is a non-negative duration in milliseconds.
Exceptions
java.lang.IllegalArgumentException if the statusReceiver from an immutable android.app.PendingIntent when caller has a target SDK of API 35 or above.

createSession

Added in API level 21
open fun createSession(params: PackageInstaller.SessionParams): Int

Create a new session using the given parameters, returning a unique ID that represents the session. Once created, the session can be opened multiple times across multiple device boots.

The system may automatically destroy sessions that have not been finalized (either committed or abandoned) within a reasonable period of time, typically on the order of a day.

Parameters
params PackageInstaller.SessionParams: This value cannot be null.
Return
Int positive, non-zero unique ID that represents the created session. This ID remains consistent across device reboots until the session is finalized. IDs are not reused during a given boot.
Exceptions
java.io.IOException if parameters were unsatisfiable, such as lack of disk space or unavailable media.
java.lang.SecurityException when installation services are unavailable, such as when called from a restricted user.
java.lang.IllegalArgumentException when SessionParams is invalid.

getActiveStagedSession

Added in API level 29
Deprecated in API level 30
open fun getActiveStagedSession(): PackageInstaller.SessionInfo?

Deprecated: Use getActiveStagedSessions as there can be more than one active staged session

Returns first active staged session, or null if there is none.

For more information on what sessions are considered active see SessionInfo#isStagedSessionActive().

getActiveStagedSessions

Added in API level 30
open fun getActiveStagedSessions(): MutableList<PackageInstaller.SessionInfo!>

Returns list of active staged sessions. Returns empty list if there is none.

For more information on what sessions are considered active see * SessionInfo#isStagedSessionActive().

Return
MutableList<PackageInstaller.SessionInfo!> This value cannot be null.

getAllSessions

Added in API level 21
open fun getAllSessions(): MutableList<PackageInstaller.SessionInfo!>

Return list of all known install sessions, regardless of the installer. Callers need to either declare <queries> element with the specific package name in the app's manifest, have the android.permission.QUERY_ALL_PACKAGES, or be the session owner to retrieve these details.

Return
MutableList<PackageInstaller.SessionInfo!> This value cannot be null.

getMySessions

Added in API level 21
open fun getMySessions(): MutableList<PackageInstaller.SessionInfo!>

Return list of all known install sessions owned by the calling app.

Return
MutableList<PackageInstaller.SessionInfo!> This value cannot be null.

getSessionInfo

Added in API level 21
open fun getSessionInfo(sessionId: Int): PackageInstaller.SessionInfo?

Return details for a specific session. Callers need to either declare <queries> element with the specific package name in the app's manifest, have the android.permission.QUERY_ALL_PACKAGES, or be the session owner to retrieve these details.

Return
PackageInstaller.SessionInfo? details for the requested session, or null if the session does not exist.

getStagedSessions

Added in API level 29
open fun getStagedSessions(): MutableList<PackageInstaller.SessionInfo!>

Return list of all staged install sessions. Callers need to either declare <queries> element with the specific package name in the app's manifest, have the android.permission.QUERY_ALL_PACKAGES, or be the session owner to retrieve these details.

Return
MutableList<PackageInstaller.SessionInfo!> This value cannot be null.

installExistingPackage

Added in API level 29
open fun installExistingPackage(
    packageName: String,
    installReason: Int,
    statusReceiver: IntentSender?
): Unit

Install the given package, which already exists on the device, for the user for which this installer was created.

This will all restricted permissions.
Requires android.Manifest.permission#INSTALL_PACKAGES and android.Manifest.permission.INSTALL_EXISTING_PACKAGES

Parameters
packageName String: The package to install. This value cannot be null.
installReason Int: Reason for install. Value is android.content.pm.PackageManager#INSTALL_REASON_UNKNOWN, android.content.pm.PackageManager#INSTALL_REASON_POLICY, android.content.pm.PackageManager#INSTALL_REASON_DEVICE_RESTORE, android.content.pm.PackageManager#INSTALL_REASON_DEVICE_SETUP, android.content.pm.PackageManager#INSTALL_REASON_USER, or android.content.pm.PackageManager.INSTALL_REASON_ROLLBACK
statusReceiver IntentSender?: Where to deliver the result of the operation indicated by the extra EXTRA_STATUS. Refer to the individual status codes on how to handle them. This value may be null.

openSession

Added in API level 21
open fun openSession(sessionId: Int): PackageInstaller.Session

Open an existing session to actively perform work. To succeed, the caller must be the owner of the install session.

Return
PackageInstaller.Session This value cannot be null.
Exceptions
java.io.IOException if parameters were unsatisfiable, such as lack of disk space or unavailable media.
java.lang.SecurityException when the caller does not own the session, or the session is invalid.

registerSessionCallback

Added in API level 21
open fun registerSessionCallback(callback: PackageInstaller.SessionCallback): Unit

Register to watch for session lifecycle events. The callers need to be the session owner or have the android.permission.QUERY_ALL_PACKAGES to watch for these events.

Parameters
callback PackageInstaller.SessionCallback: This value cannot be null.

registerSessionCallback

Added in API level 21
open fun registerSessionCallback(
    callback: PackageInstaller.SessionCallback,
    handler: Handler
): Unit

Register to watch for session lifecycle events. No special permissions are required to watch for these events.

Parameters
handler Handler: to dispatch callback events through, otherwise uses calling thread. This value cannot be null.
callback PackageInstaller.SessionCallback: This value cannot be null.

uninstall

Added in API level 21
open fun uninstall(
    packageName: String,
    statusReceiver: IntentSender
): Unit

Uninstall the given package, removing it completely from the device. This method is available to:

  • the current "installer of record" for the package
  • the device owner
  • the affiliated profile owner

Requires android.Manifest.permission#DELETE_PACKAGES or android.Manifest.permission#REQUEST_DELETE_PACKAGES

Parameters
packageName String: The package to uninstall. This value cannot be null.
statusReceiver IntentSender: Where to deliver the result of the operation indicated by the extra EXTRA_STATUS. Refer to the individual status codes on how to handle them. This value cannot be null.

uninstall

Added in API level 26
open fun uninstall(
    versionedPackage: VersionedPackage,
    statusReceiver: IntentSender
): Unit

Uninstall the given package with a specific version code, removing it completely from the device. If the version code of the package does not match the one passed in the versioned package argument this method is a no-op. Use PackageManager#VERSION_CODE_HIGHEST to uninstall the latest version of the package.

This method is available to:

  • the current "installer of record" for the package
  • the device owner
  • the affiliated profile owner

Requires android.Manifest.permission#DELETE_PACKAGES or android.Manifest.permission#REQUEST_DELETE_PACKAGES
Parameters
versionedPackage VersionedPackage: The versioned package to uninstall. This value cannot be null.
statusReceiver IntentSender: Where to deliver the result of the operation indicated by the extra EXTRA_STATUS. Refer to the individual status codes on how to handle them. This value cannot be null.

uninstall

Added in API level 34
open fun uninstall(
    versionedPackage: VersionedPackage,
    flags: Int,
    statusReceiver: IntentSender
): Unit

Uninstall the given package with a specific version code, removing it completely from the device. This method is only available to the current "installer of record" for the package. If the version code of the package does not match the one passed in the versioned package argument this method is a no-op. Use PackageManager#VERSION_CODE_HIGHEST to uninstall the latest version of the package.
Requires android.Manifest.permission#DELETE_PACKAGES or android.Manifest.permission#REQUEST_DELETE_PACKAGES

Parameters
versionedPackage VersionedPackage: The versioned package to uninstall. This value cannot be null.
flags Int: Flags for uninstall. Value is either 0 or a combination of android.content.pm.PackageManager.DELETE_KEEP_DATA, android.content.pm.PackageManager.DELETE_ALL_USERS, android.content.pm.PackageManager.DELETE_SYSTEM_APP, android.content.pm.PackageManager.DELETE_DONT_KILL_APP, and android.content.pm.PackageManager.DELETE_CHATTY
statusReceiver IntentSender: Where to deliver the result of the operation indicated by the extra EXTRA_STATUS. Refer to the individual status codes on how to handle them. This value cannot be null.

uninstallExistingPackage

Added in API level 31
open fun uninstallExistingPackage(
    packageName: String,
    statusReceiver: IntentSender?
): Unit

Uninstall the given package for the user for which this installer was created if the package will still exist for other users on the device.
Requires android.Manifest.permission#DELETE_PACKAGES

Parameters
packageName String: The package to uninstall. This value cannot be null.
statusReceiver IntentSender?: Where to deliver the result of the operation indicated by the extra EXTRA_STATUS. Refer to the individual status codes on how to handle them. This value may be null.

unregisterSessionCallback

Added in API level 21
open fun unregisterSessionCallback(callback: PackageInstaller.SessionCallback): Unit

Unregister a previously registered callback.

Parameters
callback PackageInstaller.SessionCallback: This value cannot be null.

updateSessionAppIcon

Added in API level 21
open fun updateSessionAppIcon(
    sessionId: Int,
    appIcon: Bitmap?
): Unit

Update the icon representing the app being installed in a specific session. This should be roughly ActivityManager#getLauncherLargeIconSize() in both dimensions.

Parameters
appIcon Bitmap?: This value may be null.
Exceptions
java.lang.SecurityException when the caller does not own the session, or the session is invalid.

updateSessionAppLabel

Added in API level 21
open fun updateSessionAppLabel(
    sessionId: Int,
    appLabel: CharSequence?
): Unit

Update the label representing the app being installed in a specific session.

Parameters
appLabel CharSequence?: This value may be null.
Exceptions
java.lang.SecurityException when the caller does not own the session, or the session is invalid.

waitForInstallConstraints

Added in API level 34
open fun waitForInstallConstraints(
    packageNames: MutableList<String!>,
    constraints: PackageInstaller.InstallConstraints,
    callback: IntentSender,
    timeoutMillis: Long
): Unit

Similar to checkInstallConstraints(java.util.List,android.content.pm.PackageInstaller.InstallConstraints,java.util.concurrent.Executor,java.util.function.Consumer), but the callback is invoked only when the constraints are satisfied or after timeout.

Note: the device idle constraint might take a long time to evaluate. The system will ensure the constraint is evaluated completely before handling timeout.

Parameters
packageNames MutableList<String!>: a list of package names to check the constraints for installation This value cannot be null.
constraints PackageInstaller.InstallConstraints: the constraints for installation. This value cannot be null.
callback IntentSender: Called when the constraints are satisfied or after timeout. Intents sent to this callback contain: Intent#EXTRA_PACKAGES for the input package names, EXTRA_INSTALL_CONSTRAINTS for the input constraints, EXTRA_INSTALL_CONSTRAINTS_RESULT for the result. This value cannot be null.
timeoutMillis Long: The maximum time to wait, in milliseconds until the constraints are satisfied. Valid range is from 0 to one week. 0 means the callback will be invoked immediately no matter constraints are satisfied or not. Value is a non-negative duration in milliseconds.
Exceptions
java.lang.SecurityException if the given packages' installer of record doesn't match the caller's own package name or the installerPackageName set by the caller doesn't match the caller's own package name.