java.lang.Object | |
↳ | com.datalogic.device.app.PackageInstallerSession |
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(Context)
.
PackageInstallerListener
that will be used to handle the
result of the commands invoked on the session.
PackageInstallerSession
calling createSession(PackageInstallerListener)
.
The createSession(PackageInstallerListener)
method takes as parameters the instance of PackageInstallerListener
created at the previous step.
openSession()
.
install(String, boolean)
to install the first application.
install(String, boolean)
to install the second application.
closeSession()
.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Call this method to execute the commands queued in the session.
| |||||||||||
Call this method to install the application contained within the .apk file specified by apk.
| |||||||||||
Call this method to start a session.
| |||||||||||
Call this method to unistall an application installed on the device.
| |||||||||||
Call this method to upgrade an application installed on the device.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
android.content.ServiceConnection
|
Call this method to execute the commands queued in the session.
The commands will be executed in best effort.
The command execution is asynchronous.
The results of each command will be delivered in a unique ordered list through the listener onResult(List
method.
Do not suspend the UIThread while waiting for the result of the method otherwise an application’s deadlock can occur.
Call this method to install the application contained within the .apk file specified by apk.
The method must be called after having called the openSession()
.
The method is queued internally and executed only when the closeSession()
is called.
The result of the command is received through the listener method onResult(List
.
Example:
PackageInstaller packageInstaller = new PackageInstaller(context);
PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List
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. NOTE: Running on an Android 11 device, until Datalogic SDK v1.32, an user App can install an APK only using a path of the external storage (WRITE_EXTERNAL_STORAGE permission to be granted by App to store the APK) or any path not requiring memory permissions to access (e.g Downloads). On the contrary, if the calling App stores the APK into the internal memory, the API will be not able to install the APK due to the missing privilages for accessing to the internal memory of the calling App. From Datalogic SDK v1.33, instead, the API is able to install an APK stored into the internal memory of the calling App. |
---|---|
force | boolean true force the upgrade in case the application is already installed,
otherwise the upgrade is refused. |
int
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.
|
---|
Call this method to start a session.
After this method, call the commands install, uninstall, upgrade to be executed.
The commands will be queued and executed only when the closeSession() method is called.
The commands will be executed in best effort.
The results of each command will be delivered in a unique ordered list through the onResult(List
method.
int
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.
|
---|
Call this method to unistall an application installed on the device.
The method must be called after having called the openSession()
.
The method is queued internally and executed when the closeSession()
is called.
The result of the command is received through the listener method onResult(List
.
Example:
PackageInstaller packageInstaller = new PackageInstaller(context);
PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List
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
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.
|
---|
Call this method to upgrade an application installed on the device.
The method must be called after having called the openSession()
.
The method is queued internally and executed when the closeSession()
is called.
The result of the command is received through the listener method onResult(List
.
Example:
PackageInstaller packageInstaller = new PackageInstaller(context);
PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List
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. NOTE: Running on an Android 11 device, until Datalogic SDK v1.32, an user App can upgrade an APK only using a path of the external storage (WRITE_EXTERNAL_STORAGE permission to be granted by App to store the APK) or any path not requiring memory permissions to access (e.g Downloads). On the contrary, if the calling App stores the APK into the internal memory, the API will be not able to upgrade the APK due to the missing privilages for accessing to the internal memory of the calling App. From Datalogic SDK v1.33, instead, the API is able to upgrade an APK stored into the internal memory of the calling App. |
---|
int
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.
|
---|