Search code examples
firefoxsharefirefox-os

add a share button in Firefox OS application


I am creating a firefox OS application, I want the user to be able to share a link through any application installed and eligible (facebook, twitter etc). I saw android has this kind of feature and firefox OS has it as well, as I saw it in one of it's built in applications. Went through Web API, didn't find a suitable match,

Any ideas how to do it?


Solution

  • This is the intended use of the Web Activity API . The idea is that applications register to handle activities like share. The Firefox OS Boiler Plate app has several examples of using Web Activities. In that example a user could share a url using code like:

    var share = document.querySelector("#share");
    if (share) {
        share.onclick = function () {
            new MozActivity({
                name: "share",
                data: {
                    number: 1,
                    url: "http://robertnyman.com"
                }
            });
        };
    }
    

    Any app that handles the share activity will be shown allowing the user to pick the proper app to handle the share.