public class PackageInstaller
extends java.lang.Object
PackageInstaller gives developers the ability to install, uninstall and
upgrade applications in unattended/silent mode.
The install/uninstall/upgrade/selfUpgrade methods are asynchronous. An object that implements PackageInstallerListener
must be passed to PackageInstaller to be able to handle the result. To install an application do the following steps:
PackageInstaller(android.content.Context).
PackageInstallerListener that will be used to handle the
result of the command. This object must be passed as parameter to
the install method.
install(java.lang.String, boolean, com.datalogic.device.app.PackageInstallerListener). The method onResult of the
listener will be called when the install session has completely
finished, either with success or failure.
To uninstall an application do the following steps:
PackageInstaller(android.content.Context).
PackageInstallerListener that will be used to handle the
result of the command. This object must be passed as parameter to the uninstall method.
uninstall(java.lang.String, com.datalogic.device.app.PackageInstallerListener). The method onResult
of the listener will be called when the uninstall session has completely
finished, either with success or failure.
To upgrade an application do the following steps:
PackageInstaller(android.content.Context).
PackageInstallerListener that will be used to handle the
result of the command. This object must be passed as parameter to the upgrade method.
upgrade(java.lang.String, com.datalogic.device.app.PackageInstallerListener). The method onResult
of the listener will be called when the upgrade session has completely
finished, either with success or failure.
To execute more install/uninstall/upgrade methods and be notified of the results when all the methods have completed, do the following steps:
PackageInstaller(android.content.Context).
PackageInstallerListener that will be used to handle the
result of the commands. This object must be passed as parameter to the createSession method.
PackageInstallerSession with createSession(com.datalogic.device.app.PackageInstallerListener).
PackageInstallerSession.openSession().
PackageInstallerSession.install(java.lang.String, boolean), PackageInstallerSession.uninstall(java.lang.String), PackageInstallerSession.upgrade(java.lang.String) that
suite you.
PackageInstallerSession.closeSession().
To upgrade the current application do the following steps:
PackageInstaller(android.content.Context).
selfUpgrade(java.lang.String) passing as parameter the name of the package to be used to upgrade the current application.
| Constructor and Description |
|---|
PackageInstaller(android.content.Context context)
This is the constructor of PackageInstaller.
|
| Modifier and Type | Method and Description |
|---|---|
PackageInstallerSession |
createSession(PackageInstallerListener listener)
Call this method to create a
PackageInstallerSession object. |
int |
install(java.util.ArrayList<java.lang.String> apks,
boolean atomic,
PackageInstallerListener listener)
Call this method to install the applications contained within the .apk files specified by apks.
|
int |
install(java.lang.String apk,
boolean force,
PackageInstallerListener listener)
Call this method to install the application contained within the .apk file specified by apk.
|
int |
selfUpgrade(java.lang.String apk)
Call this method to upgrade the current application.
|
int |
uninstall(java.lang.String packageName,
PackageInstallerListener listener)
Call this method to unistall an application installed on the device.
|
int |
upgrade(java.lang.String apk,
PackageInstallerListener listener)
Call this method to upgrade an application installed on the device.
|
public PackageInstaller(android.content.Context context)
context - Context context of the caller applicationPackageInstallerException - in case of error.public PackageInstallerSession createSession(PackageInstallerListener listener)
PackageInstallerSession object.
The method can be used to request a session on which it will be possible
to group the execution of a sequence of install/uninstall/upgrade commands.listener - PackageInstallerListener instance that implements
the method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>) to handle the result of methods executed in the session.int
PackageInstallerException.SUCCESS in case of success,
otherwise a possible error code, matching one of the PackageInstallerException error constants.PackageInstallerException - in case of error when exceptions are enabled through the ErrorManager singleton.public int selfUpgrade(java.lang.String apk)
PackageInstallerException error constants, but when exceptions are enabled @throws PackageInstallerException. int: a possible error code, matching one of the PackageInstallerException error constants.
String: an error string message.
String: Package Name of the application.
apk - String full path of the .apk to be used to upgrade the current application.int
PackageInstallerException.SUCCESS in case of success,
otherwise a possible error code, matching one of the PackageInstallerException error constants.PackageInstallerException - in case of error, when exceptions are enabled through the ErrorManager singleton.public int install(java.lang.String apk,
boolean force,
PackageInstallerListener listener)
PackageInstallerSession.
The result of the command is received through the listener method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>).
Do not suspend the UIThread while waiting for the result of the method otherwise an application’s deadlock can occur.
PackageInstaller packageInstaller = new PackageInstaller(context);PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List results) {...}}; packageInstaller.install("/dir1/dir11/dir116/pkg1.apk", false, listener);apk - String full path of the .apk to be installed.force - boolean true force the upgrade in case the application is already installed,
otherwise the upgrade is refused.listener - PackageInstallerListener instance that implements
the method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>) to handle the result of the method.int
PackageInstallerException.SUCCESS in case of success,
otherwise a possible error code, matching one of the PackageInstallerException error constants.PackageInstallerException - in case of error, when exceptions are enabled through the ErrorManager singleton.public int install(java.util.ArrayList<java.lang.String> apks,
boolean atomic,
PackageInstallerListener listener)
PackageInstallerSession.
The result of the command is received through the listener method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>).
Do not suspend the UIThread while waiting for the result of the method otherwise an application’s deadlock can occur.
public int install(ArrayList pkgs, boolean atomic)
PackageInstaller packageInstaller = new PackageInstaller(context);PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List results) {...}}; ArrayList apks = new ArrayList(); apks.add("/dir1/dir11/dir116/pkg1.apk"); apks.add("/dir1/dir11/dir116/pkg2.apk");packageInstaller.install(apks, false);pkgs - ArrayList list of the .apks files to be installedatomic - boolean true if "apks" lists the multiple split APKs of the application to be installedlistener - PackageInstallerListener instance that implements
the method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>) to handle the result of the method.int
PackageInstallerException.SUCCESS in case of success,
otherwise a possible error code, matching one of the PackageInstallerException error constants.PackageInstallerException - in case of error, when exceptions are enabled through the ErrorManager singleton.public int uninstall(java.lang.String packageName,
PackageInstallerListener listener)
PackageInstallerSession.
The result of the command is received through the listener method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>).
Do not suspend the UIThread while waiting for the result of the method otherwise an application’s deadlock can occur.
PackageInstaller packageInstaller = new PackageInstaller(context);PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List results) {...}}; packageInstaller.uninstall("com.example.helloandroid", listener);packageName - String package name of the application to be uninstalled.listener - PackageInstallerListener instance that implements
the method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>) to handle the result of the method.int
PackageInstallerException.SUCCESS in case of success,
otherwise a possible error code, matching one of the PackageInstallerException error constants.PackageInstallerException - in case of error, when exceptions are enabled through the ErrorManager singleton.public int upgrade(java.lang.String apk,
PackageInstallerListener listener)
PackageInstallerSession.
The result of the command is received through the listener method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>).
PackageInstaller packageInstaller = new PackageInstaller(context);PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List results) {...}}; packageInstaller.upgrade("/dir1/dir11/dir116/pkg1_v2.apk", listener);apk - String full path of the .apk to be used to upgrade the application already installed that has the same Package Name of this .apk.listener - PackageInstallerListener instance that implements
the method PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>) to handle the result of the method.int
PackageInstallerException.SUCCESS in case of success,
otherwise a possible error code, matching one of the PackageInstallerException error constants.PackageInstallerException - in case of error, when exceptions are enabled through the ErrorManager singleton.