public class PackageInstallerSession
extends java.lang.Object
implements android.content.ServiceConnection
PackageInstallerSession gives developers the ability to group the execution of a sequence of install, uninstall and
upgrade commands.
Once the session is created, the commands install, uninstall, upgrade must be called inside a transaction.
A transaction is opened calling openSession() and closed and commited calling closeSession().
To install two applications using a session do the following steps:
PackageInstaller.PackageInstaller(android.content.Context).
PackageInstallerListener that will be used to handle the
result of the commands invoked on the session.
PackageInstallerSession calling PackageInstaller.createSession(com.datalogic.device.app.PackageInstallerListener).
The PackageInstaller.createSession(com.datalogic.device.app.PackageInstallerListener) method takes as parameters the instance of PackageInstallerListener created at the previous step.
openSession().
install(java.lang.String, boolean) to install the first application.
install(java.lang.String, boolean) to install the second application.
closeSession().
| Constructor and Description |
|---|
PackageInstallerSession() |
| Modifier and Type | Method and Description |
|---|---|
int |
closeSession()
Call this method to execute the commands queued in the session.
|
int |
install(java.util.ArrayList<java.lang.String> apks,
boolean atomic)
Call this method to install the applications contained within the .apk files specified by apks.
|
int |
install(java.lang.String apk,
boolean force)
Call this method to install the application contained within the .apk file specified by apk.
|
void |
onServiceConnected(android.content.ComponentName className,
android.os.IBinder binder)
Callback implemented to receive the asynchronous result of the bindService request.
|
void |
onServiceDisconnected(android.content.ComponentName className)
Callback implemented to receive the notify that the bind to the service is lost due to a crash of the service.
|
int |
openSession()
Call this method to start a session.
|
int |
uninstall(java.lang.String packageName)
Call this method to unistall an application installed on the device.
|
int |
upgrade(java.lang.String apk)
Call this method to upgrade an application installed on the device.
|
public int openSession()
PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>) 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 closeSession()
PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>) method.
Do not suspend the UIThread while waiting for the result of the method otherwise an application’s deadlock can occur.public void onServiceConnected(android.content.ComponentName className,
android.os.IBinder binder)
onServiceConnected in interface android.content.ServiceConnectionpublic void onServiceDisconnected(android.content.ComponentName className)
onServiceDisconnected in interface android.content.ServiceConnectionpublic int install(java.lang.String apk,
boolean force)
openSession(). closeSession() is called. PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>).
PackageInstaller packageInstaller = new PackageInstaller(context);PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List results) {...}}; PackageInstallerSession session = packageInstaller.createSession(listener);session.openSession();session.install("/dir1/dir11/dir116/pkg1.apk", force);session.closeSession();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.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)
openSession(). closeSession() is called. PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>).
public int install(ArrayList pkgs, boolean atomic)
PackageInstaller packageInstaller = new PackageInstaller(context);PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List results) {...}}; PackageInstallerSession session = packageInstaller.createSession(listener);session.openSession(); ArrayList apks = new ArrayList(); apks.add("/dir1/dir11/dir116/pkg1.apk"); apks.add("/dir1/dir11/dir116/pkg2.apk");session.install(apks, false);session.closeSession();apks - ArrayList list of the full path of the .apk files to be installed.atomic - boolean true if "apks" lists the multiple split APKs of the application to be installed.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)
openSession(). closeSession() is called. PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>).
PackageInstaller packageInstaller = new PackageInstaller(context);PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List results) {...}}; PackageInstallerSession session = packageInstaller.createSession(listener);session.openSession();session.upgrade("/dir1/dir11/dir116/pkg1_v2.apk");session.closeSession();apk - String full path of the .apk to be used to upgrade the application already installed with the same Package Name of this .apk.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)
openSession(). closeSession() is called. PackageInstallerListener.onResult(java.util.List<com.datalogic.device.app.PackageInstallerResult>).
PackageInstaller packageInstaller = new PackageInstaller(context);PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List results) {...}}; PackageInstallerSession session = packageInstaller.createSession(listener);session.openSession();session.uninstall("com.example.helloandroid");session.closeSession();packageName - String package name of the application to be uninstalled.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.