With this snippet you can install apps, as a parameter you have to enter the path to the app which is on SD card.
function install(param) {
var request = sdcard.get(param);
request.onsuccess = function() {
var file = this.result;
installPkg(file);
};
request.onerror = function() {
console.log("Installation error: " + this.error);
};
}
function installPkg(packageFile) {
navigator.mozApps.mgmt
.import(packageFile)
.then(function(e) {
})
.catch((error) => {
//alert("Installation error: " + error.name + " " + error.message);
if (error.name === "noMetadata") {
}
if (error.name === "AppAlreadyInstalled") {
("Installation error: App Already Installed.");
}
if (error.name === "InvalidPrivilegeLevel") {
});
}
The navigator.mozApps.mgmt.getAll()
function returns a request object, which can be assigned onsuccess
and onerror
events.
When onsuccess
is called, the request's result
property contains an array of app objects.
The following code shows a list of apps in an alert box:
var request = navigator.mozApps.mgmt.getAll();
var list = "";
request.onsuccess = function(){
request.result.forEach(function(app){
list += "App name: " + app.manifest.name + "\n";
});
alert(list);
}
manifest
: The manifest of the app, represented as an objectmanifestURL
: The URL of the app manifestlaunch([entry_point])
: Launch the appTo uninstall an app, pass the app object to navigator.mozApps.mgmt.uninstall
.