Question

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.

Was it helpful?

Solution

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!

OTHER TIPS

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:

http://jsfiddle.net/F6aEC/

and you also can open this link in your firefox os phone, install and test it:

http://jsfiddle.net/F6aEC/fxos.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top