This API provides functionalities to install or uninstall packages, and retrieve information about installed packages. It also provides a listener method so that an application can be notified when there is a change on the installed packages. For more information on the Package features, see Package Guide.
Since: 2.1
A unique ID for an installed package.
typedef DOMString PackageId;
This interface defines what is instantiated by the Tizen object from the Tizen Platform.
[NoInterfaceObject] interface PackageManagerObject { readonly attribute PackageManager package; };
Tizen implements PackageManagerObject;
The tizen.package object allows access to Package API functionality.
This interface defines the package manager.
[NoInterfaceObject] interface PackageManager { void install(DOMString packageFileURI, PackageProgressCallback progressCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void uninstall(PackageId id, PackageProgressCallback progressCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void getPackagesInfo(PackageInformationArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); PackageInformation getPackageInfo(optional PackageId? id) raises(WebAPIException); void setPackageInfoEventListener(PackageInformationEventCallback eventCallback) raises(WebAPIException); void unsetPackageInfoEventListener() raises(WebAPIException); };
install
Installs a package with a specified file on a device.
void install(DOMString packageFileURI, PackageProgressCallback progressCallback, optional ErrorCallback? errorCallback);
This API provides a way to notify the progress and completion of an installation request through PackageProgressCallback.
The ErrorCallback() is launched with these error types:
Privilege level: platform
Privilege: http://tizen.org/privilege/packagemanager.install
Remark : Virtual path cannot be used for the parameter. First, you need to convert any virtual path to a file URI path using the resolve function in the Filesystem API before passing it to the function.
Parameters:
Exceptions:
Code example:
var onInstallation = { onprogress: function(packageId, percentage) { console.log("On installation(" + packageId + ") : progress(" + percentage + ")"); }, oncomplete: function(packageId) { console.log("Installation(" + packageId + ") Complete"); } } var onError = function (err) { console.log("Error occurred on installation : " + err.name); } // Let's assume that the "test.wgt" file exists in the downloads directory tizen.filesystem.resolve("downloads/test.wgt", function (file) { console.log("file URI : " + file.toURI()); tizen.package.install(file.toURI(), onInstallation, onError); }, function (err) { console.log("Error occurred on resolve : " + err.name); }, "r");
uninstall
Uninstalls the package with a specified package ID.
void uninstall(PackageId id, PackageProgressCallback progressCallback, optional ErrorCallback? errorCallback);
This API provides a way to notify about the progress and completion of an uninstallation request through PackageProgressCallback.
Remark : Some preloaded packages cannot be uninstalled. In this case, ErrorCallback with the UnKnownError type is launched.
var onUninstallation = { onprogress: function(packageId, percentage) { console.log("On Uninstallation(" + packageId + ") : progress(" + percentage + ")"); }, oncomplete: function(packageId) { console.log("Uninstallation(" + packageId + ") Complete"); } }; var onError = function (err) { console.log("Error occurred on installation : " + err.name); }; // Let's assume that the package ID to uninstall is "testapp001" tizen.package.uninstall("testapp001", onUninstallation, onError);
getPackagesInfo
Gets information of the installed packages.
void getPackagesInfo(PackageInformationArraySuccessCallback successCallback, optional ErrorCallback? errorCallback);
The result contains the snapshots of the installed packages information.
The errorCallback() is launched with this error type:
Privilege level: public
Privilege: http://tizen.org/privilege/package.info
function onListInstalledPackages(packages) { for (var i = 0; i < packages.length; i++) { console.log("Package id["+i+"] : " +packages[i].id); } } tizen.package.getPackagesInfo( onListInstalledPackages, function (err) {console.log("Can't obtain packages list" + err.name);});
getPackageInfo
Gets information of an installed package.
PackageInformation getPackageInfo(optional PackageId? id);
If the ID is set to null or not set at all, it returns the package information of the current application. The list of installed packages and their package IDs is obtained using getPackagesInfo().
Return value: PackageInformation The information of a package
var packageInfo = tizen.package.getPackageInfo(null); console.log("Current Package ID : " + packageInfo.id);
setPackageInfoEventListener
Sets a listener to receive notifications for any changes made to the list of installed packages.
void setPackageInfoEventListener(PackageInformationEventCallback eventCallback);
This method sets a PackageInformationEventCallback type callback that is triggered when a package is installed, removed, or updated.
The callback lasts until the unsetPackageInfoEventListener() method is called.
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'); } }; tizen.package.setPackageInfoEventListener(packageEventCallback);
unsetPackageInfoEventListener
Unsets the listener to stop receiving package notifications.
void unsetPackageInfoEventListener();
tizen.package.unsetPackageInfoEventListener();
This interface defines the general information available to an installed package.
[NoInterfaceObject] interface PackageInformation { readonly attribute PackageId id; readonly attribute DOMString name; readonly attribute DOMString iconPath; readonly attribute DOMString version; readonly attribute long totalSize; readonly attribute long dataSize; readonly attribute Date lastModified; readonly attribute DOMString author; readonly attribute DOMString description; readonly attribute ApplicationId[] appIds; };
This interface invokes the success callback with an array of PackageInformation objects as an input parameter when the installed package list is retrieved.
[Callback=FunctionOnly, NoInterfaceObject] interface PackageInformationArraySuccessCallback { void onsuccess(PackageInformation[] informationArray); };
It is used in tizen.package.getPackagesInfo().
onsuccess
Called when the asynchronous call completes successfully.
void onsuccess(PackageInformation[] informationArray);
This callback interface specifies subscriptions for any notification on the progress or completion of requests.
[Callback, NoInterfaceObject] interface PackageProgressCallback { void onprogress(PackageId id, short progress); void oncomplete(PackageId id); };
onprogress
Called while the request is in progress.
void onprogress(PackageId id, short progress);
oncomplete
Called when the request is completed.
void oncomplete(PackageId id);
This callback interface specifies methods that are invoked when a package is installed, updated, or uninstalled.
void [Callback, NoInterfaceObject] interface PackageInformationEventCallback { void oninstalled(PackageInformation info); void onupdated(PackageInformation info); void onuninstalled(PackageId id); };
oninstalled
Called when a package is installed.
void oninstalled(PackageInformation info);
onupdated
Called when a package is updated.
void onupdated(PackageInformation info);
onuninstalled
Called when a package is uninstalled.
void onuninstalled(PackageId id);
module Package { typedef DOMString PackageId; [NoInterfaceObject] interface PackageManagerObject { readonly attribute PackageManager package; }; Tizen implements PackageManagerObject; [NoInterfaceObject] interface PackageManager { void install(DOMString packageFileURI, PackageProgressCallback progressCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void uninstall(PackageId id, PackageProgressCallback progressCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void getPackagesInfo(PackageInformationArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); PackageInformation getPackageInfo(optional PackageId? id) raises(WebAPIException); void setPackageInfoEventListener(PackageInformationEventCallback eventCallback) raises(WebAPIException); void unsetPackageInfoEventListener() raises(WebAPIException); }; [NoInterfaceObject] interface PackageInformation { readonly attribute PackageId id; readonly attribute DOMString name; readonly attribute DOMString iconPath; readonly attribute DOMString version; readonly attribute long totalSize; readonly attribute long dataSize; readonly attribute Date lastModified; readonly attribute DOMString author; readonly attribute DOMString description; readonly attribute ApplicationId[] appIds; }; [Callback=FunctionOnly, NoInterfaceObject] interface PackageInformationArraySuccessCallback { void onsuccess(PackageInformation[] informationArray); }; [Callback, NoInterfaceObject] interface PackageProgressCallback { void onprogress(PackageId id, short progress); void oncomplete(PackageId id); }; [Callback, NoInterfaceObject] interface PackageInformationEventCallback { void oninstalled(PackageInformation info); void onupdated(PackageInformation info); void onuninstalled(PackageId id); }; };