java.lang.Object | |
↳ | com.datalogic.device.app.PackageInstaller |
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.
An install/uninstall/upgrade method can be executed alone calling the corresponding method of the PackageInstaller
or together with other methods grouped in a PackageInstallerSession. In the former case there will be a result callback for each method,
in the latter case there will be only one callback listing the results of each method. The methods grouped in a PackageInstallerSession
are executed in best effort.
To install an application do the following steps:
PackageInstaller(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(String, boolean, 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(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(String, 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(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(String, 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(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(PackageInstallerListener)
.
openSession()
.
install(String, boolean)
, uninstall(String)
, upgrade(String)
that
suite you.
closeSession()
.
To upgrade the current application do the following steps:
PackageInstaller(Context)
.
selfUpgrade(String)
passing as parameter the name of the package to be used to upgrade the current application.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This is the constructor of PackageInstaller.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Call this method to create a
PackageInstallerSession object. | |||||||||||
Call this method to install the application contained within the .apk file specified by apk.
| |||||||||||
Call this method to upgrade the current application.
| |||||||||||
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
|
This is the constructor of PackageInstaller.
context | Context context of the caller application |
---|
PackageInstallerException | in case of error. |
---|
Call this method to create a 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 onResult(List to handle the result of methods executed in the session. |
---|
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 install the application contained within the .apk file specified by apk.
The method is executed alone, not grouped together with other methods as can be done using a PackageInstallerSession
.
The result of the command is received through the listener method onResult(List
.
Do not suspend the UIThread while waiting for the result of the method otherwise an application’s deadlock can occur.
Example:
PackageInstaller packageInstaller = new PackageInstaller(context);
PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List
packageInstaller.install("/dir1/dir11/dir116/pkg1.apk", false, listener);
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. |
listener | PackageInstallerListener instance that implements
the method onResult(List to handle the result of the 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 upgrade the current application.
Do not suspend the UIThread while waiting for the result of the method otherwise an application’s deadlock can occur.
In case of success the intent "android.intent.action.MY_PACKAGE_REPLACED" is fired.
In case of failure:
- if the problem is found before contacting the remote service an error is returned;
the error code is one of the PackageInstallerException
error constants, but when exceptions are enabled @throws PackageInstallerException
.
- if the problem is found in the remote service the intent "com.datalogic.app.UPGRADE_ME_STATUS" is fired.
The extra data of the "com.datalogic.app.UPGRADE_ME_STATUS" are:
- android.content.pm.PackageInstaller.EXTRA_STATUS int
: a possible error code, matching one of the PackageInstallerException
error constants.
- android.content.pm.PackageInstaller.EXTRA_STATUS_MESSAGE String
: an error string message.
- android.content.pm.PackageInstaller.EXTRA_PACKAGE_NAME String
: Package Name of the application.
apk | String full path of the .apk to be used to upgrade the current application. 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.
|
---|
Call this method to unistall an application installed on the device.
The method is executed alone, not grouped together with other methods as can be done using a PackageInstallerSession
.
The result of the command is received through the listener method onResult(List
.
Do not suspend the UIThread while waiting for the result of the method otherwise an application’s deadlock can occur.
Example:
PackageInstaller packageInstaller = new PackageInstaller(context);
PackageInstallerListener listener = new PackageInstallerListener{public void onResult(List
packageInstaller.uninstall("com.example.helloandroid", listener);
packageName | String package name of the application to be uninstalled. |
---|---|
listener | PackageInstallerListener instance that implements
the method onResult(List to handle the result of the 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 upgrade an application installed on the device.
The method is executed alone, not grouped together with other methods as we can be done using a PackageInstallerSession
.
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
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. 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. |
---|---|
listener | PackageInstallerListener instance that implements
the method onResult(List to handle the result of the 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.
|
---|