Reputation: 175
I want to open an APP when one Alarm is fired. I can fire alarms with Alarm API, but I don't know how I can open the APP when the alarm is fired. Now, when the alarm is fired the APP is opened but in background.
I have Firefox OS 1.1.
Upvotes: 1
Views: 1145
Reputation: 309
You can launch any app, like this:
let request = navigator.mozApps.mgmt.getAll();
request.onsuccess = function() {
let apps = request.result;
apps.forEach(function iterateApp(app) {
if (app.origin != "origin of the app you want to launch") return;
app.launch();
});
};
request.onerror = function() {
console.log("Error: " + request.error.name);
};
Here, 'navigator.mozApps.mgmt.getAll()' returns 'pendingGetAll' object. Inside onsuccess, pendingGetAll.result(here request.result) will be an array of App objects that contains all the apps installed in the current browser or KaiOS phone.
example of app origin: app://contacts.lic.com.
You will get it inside the manifest file of the app(manifest.webapp).
Upvotes: 2
Reputation: 73
You also can use MozActivity to open another app, please reference camera and gallery apps. in camera.js:775-789 it use MozActivity to open Gallery:
var a = new MozActivity({
name: 'browse',
data: {
type: 'photos'
}
});
and you need to add avtivities in manifest.webapp for your app:
"activities": {
"browse": {
"filters": {
"type": "photos"
},
"disposition": "window"
},
...
}
there is a sample to open gallery in an app:
and you also can open this link in your firefox os phone, install and test it:
http://jsfiddle.net/F6aEC/fxos.html
Upvotes: 1
Reputation: 774
If the only app you want to launch is your app from inside your app then you can use Open Web Apps API and write code like the following:
var request = window.navigator.mozApps.getSelf();
request.onsuccess = function() {
if (request.result) {
setTimeout(function() {
request.result.launch();
}, 10000);
} else {
alert("Called from outside of an app");
}
};
request.onerror = function() {
alert("Error: " + request.error.name);
};
The above example will launch (bring in foreground) your App after 10 seconds.
request.result is an App object which describes your app.
In case you want to launch other apps, you have to use mozApps.mgmt.getAll() to find other apps (it returns as request.result an array of installed apps - App objects). To use this API your app should be a privileged one. For code examples check at gaia source code which you can find also on github.
disclaimer: In some cases mozApps.mgmt methods needs your app to be certified, I am not 100% sure if this happens with mozApps.mgmt.getAll(). If someone knows please edit my answer or leave a comment. Thanks!
Upvotes: 3