Package: Providing Information about Package Installation and Installed Packages
This tutorial demonstrates how you can manage packages and retrieve information about them.
The Package API is mandatory for both Tizen mobile and wearable profiles, which means that it is supported in all mobile and wearable devices. All mandatory APIs are supported on the Tizen Emulators.
Warm-up
Become familiar with the Package API basics by learning about:
-
Retrieving Package Information
Display a list of installed packages on the device, and retrieve package information, such as name, ID, icon path, and version.
-
Managing Packages
Install or uninstall packages.
-
Receiving Package Change Notifications
Receive notifications if packages are installed, updated, or uninstalled.
Retrieving Package Information
Learning how to retrieve information about installed packages allows you to manage device packages from your application:
-
To retrieve a list of installed packages, use the getPackagesInfo() method of the PackageManager interface (in mobile and wearable applications):
function onListInstalledPackages(lists) { console.log("The number of installed package is " + lists.length); } tizen.package.getPackagesInfo(onListInstalledPackages);
The list of installed packages is returned to the PackageInformationArraySuccessCallback() methods as an array of PackageInformation objects (in mobile and wearable applications).
-
To retrieve basic package information, use the getPackageInfo() method of the PackageManager interface, specifying the package ID. If no package ID is set, the method retrieves information of the application package calling the method.
var packageInfo = tizen.package.getPackageInfo("org.tizen.calculator");
Managing Packages
Learning how to install and uninstall packages is a basic package management skill:
-
To install a package, use the install() method of the PackageManager interface (in mobile and wearable applications), specifying the local package installation path on your device. You can retrieve the installation progress using the PackageProgressCallback interface (in mobile and wearable applications).
var onInstallation = { onprogress: function(packageId, percentage) { console.log("On installation(" + packageId + "): progress(" + percentage + ")"); }, oncomplete: function(packageId) { console.log("Installation(" + packageId + ") Complete"); } }; tizen.filesystem.resolve("downloads/test.wgt", function(packageFile) { tizen.package.install(packageFile.toURI(), onInstallation); });
-
To uninstall a package, use the uninstall() method of the PackageManager interface, specifying the package ID. You can retrieve the uninstallation progress using the PackageProgressCallback interface.
var onUninstallation = { onprogress: function(packageId, percentage) { console.log("On uninstallation(" + packageId + "): progress(" + percentage + ")"); }, oncomplete: function(packageId) { console.log("Uninstallation(" + packageId + ") Complete"); } }; tizen.package.uninstall("TEST_APP_ID", onUninstallation);
Receiving Package Change Notifications
Learning to receive notifications when the list of installed packages changes allows you to manage device packages from your application:
-
Define the event handlers for different notifications using the PackageInformationEventCallback listener interface (in mobile and wearable applications):
var packageEventCallback = { oninstalled: function(packageInfo) { console.log("The package " + packageInfo.name + " is installed"); }, onupdated: function(packageInfo) { console.log("The package " + packageInfo.name + " is updated"); }, onuninstalled: function(packageId) { console.log("The package " + packageId + " is uninstalled"); } };
-
Register the listener to use the defined event handlers with the setPackageInfoEventListener() method of the PackageManager interface (in mobile and wearable applications):
tizen.package.setPackageInfoEventListener(packageEventCallback);
-
To stop receiving notifications, use the unsetPackageInfoEventListener() method of the PackageManager interface:
tizen.package.unsetPackageInfoEventListener();