3

I am wondering if there is a way for a Firefox OS app to broadcast an event to all other apps and for the interested apps to hook on that event and trigger a corresponding action.

An example of use case I have in mind: the Camera app broadcasts the event "picture taken" and another app hooks on this event and take some action on the new picture that has been taken (for example, uploads it to a server).

Alessandro Cosentino
  • 2,268
  • 1
  • 21
  • 30

2 Answers2

2

There's not currently a web API in Firefox OS to broadcast events to all open and/or interested apps.

For your particular use-case of apps being notified when a new photo is taken by Camera, the best approach is probably to open DeviceStorage for "pictures" and listen to "change" events.

Documentation for this is at:

https://developer.mozilla.org/en-US/docs/Web/API/DeviceStorage

Alternatives exist but are more restricted functionally, and available in fewer releases and contexts:

Note: For every example here, your app would have to be running for it to work. There's no mechanism for waking an app up when a specific action or event occurs. Web Activities is the closest API for event-specific app loading. Timers API is for non-specific app loading.

Dietrich Ayala
  • 921
  • 6
  • 9
  • Another solution, which I have heard from 'dmarcos' on the #gaia channel is to abuse of the Settings API, by modifying and listening for settings values. It's not recommended, but it's been done in the past to simulate cross app events. – Alessandro Cosentino Jan 13 '15 at 21:56
  • Yeah that was #3 in my list above. Kinda hacky, and doesn't work for non-certified apps yet :) – Dietrich Ayala Jan 14 '15 at 20:33
  • Sorry, exactly the same :) I had misread your #3. I accepted the answer, exactly what I was looking for, thanks. – Alessandro Cosentino Jan 14 '15 at 21:17
0

From this article[1]:

App authors can build an app that will handle one or more activities. That means that the app will be callable by another app to perform some specific actions defined by the activity. For example, let's pretend we want to build a photo manager. It could be used by another application to pick a photo. As an activity handler our app will become part of the other application's workflow.

[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Activities

Cod1ngFree
  • 1,873
  • 6
  • 21
  • 33
  • I am aware of Web Activities, but what I want to do is not achievable with that. – Alessandro Cosentino Jan 13 '15 at 21:52
  • Afaik, the Simple Push Notifications API can be used to wake an app up too. Maybe it's too complex for a simple interaction, but that (mixed with the Alarm API) is what the Whatsapp clients are doing. – Cod1ngFree Jan 14 '15 at 09:16