Package Information
You can retrieve detailed information about packages, such as package name, icon path, version details, and package ID. You can receive notifications if packages are updated or removed, or new packages are installed. You can also perform package management tasks, such as installing or uninstalling packages.
The Package API is mandatory for Tizen Mobile, Wearable, and TV profiles, which means that it is supported on all mobile, wearable, and TV devices. All mandatory APIs are supported on the Tizen emulators.
The main package information features are:
-
Package management
You can install or uninstall packages.
-
Package information retrieval
You can display a list of installed packages on the device, and retrieve package information, such as name, ID, icon path, and version.
-
Package change notifications
You can receive notifications when packages are installed, updated, or uninstalled.
Prerequisites
To use the Package API (in mobile, wearable, and TV applications), the application has to request permission by adding the following privileges to the config.xml
file:
<tizen:privilege name="http://tizen.org/privilege/package.info"/>
<tizen:privilege name="http://tizen.org/privilege/packagemanager.install"/>
Retrieve package information
You can retrieve information about packages in various ways:
- Retrieve information about installed packages using the
getPackageInfo()
andgetPackagesInfo()
methods of thePackageManager
interface (in mobile, wearable, and TV applications). - Use the
PackageInformation
interface (in mobile, wearable, and TV applications) to retrieve information about installed packages, such as name, icon path, and version.
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 thePackageManager
interface: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 ofPackageInformation
objects. -
To retrieve basic package information, use the
getPackageInfo()
method of thePackageManager
interface, specifying the package ID. If no package ID is set, the method retrieves the information for the application package calling the method:var packageInfo = tizen.package.getPackageInfo('org.tizen.calculator');
Manage packages
You can manage the package installation using the install()
and uninstall()
methods of the PackageManager
interface (in mobile, wearable, and TV applications). Additionally, you can receive notifications of the installation and uninstallation progress using the PackageProgressCallback
interface (in mobile, wearable, and TV applications)
Learning how to install and uninstall packages is a basic package management skill:
-
To install a package, use the
install()
method of thePackageManager
interface, specifying the local package installation path on your device. You can retrieve the installation progress using thePackageProgressCallback
interface: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 thePackageManager
interface, specifying the package ID. You can retrieve the uninstallation progress using thePackageProgressCallback
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);
Receive package change notifications
You can receive notifications of changes in the list of installed packages. The setPackageInfoEventListener()
method of the PackageManager
interface (in mobile, wearable, and TV applications) registers an event listener for changes in the installed packages list. To unsubscribe the listener, use the unsetPackageInfoEventListener()
method. You can use the PackageInformationEventCallback
interface (in mobile, wearable, and TV applications) to define listeners for receiving 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: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 thePackageManager
interface:tizen.package.setPackageInfoEventListener(packageEventCallback);
-
To stop receiving notifications, use the
unsetPackageInfoEventListener()
method of thePackageManager
interface:tizen.package.unsetPackageInfoEventListener();
Related information
- Dependencies
- Tizen 2.4 and Higher for Mobile
- Tizen 2.3.1 and Higher for Wearable
- Tizen 3.0 and Higher for TV