如何更改Firefox OS设备上的壁纸?

时间:2014-04-11 20:09:41

标签: javascript api firefox firefox-os b2g

我最近一直在学习Firefox OS / B2G。我知道有大量的API能够从壁纸库中获取图像,更改设置和设置提醒(仅举几例)。但是,我完全不知道如何更改壁纸,或者实际上,如果可能的话。如果这是一个愚蠢的问题,请道歉。非常感谢提前。

1 个答案:

答案 0 :(得分:1)

您可以使用共享活动

来执行此操作
// imgToShare is the image you want to set as wallpaper
var shareImage = document.querySelector("#share-image"),
    imgToShare = document.querySelector("#image-to-share");

if (shareImage && imgToShare) {
    shareImage.onclick = function () {
        if(imgToShare.naturalWidth > 0) {
            // Create dummy canvas
            var blobCanvas = document.createElement("canvas");
            blobCanvas.width = imgToShare.width;
            blobCanvas.height = imgToShare.height;

            // Get context and draw image
            var blobCanvasContext = blobCanvas.getContext("2d");
            blobCanvasContext.drawImage(imgToShare, 0, 0);

            // Export to blob and share through a Web Activitiy
            blobCanvas.toBlob(function (blob) {
                new MozActivity({
                    name: "share",
                    data: {
                        type: "image/*",
                        number: 1,
                        blobs: [blob]
                    }
                });
            });
        }
        else {
            alert("Image failed to load, can't be shared");
        }
    };
}

您可以使用Firefox OS样板https://github.com/robnyman/Firefox-OS-Boilerplate-App/测试实时示例。