2

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

4

1 回答 1

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/测试一个实时示例。

于 2014-04-14T15:54:37.850 回答