我最近一直在学习Firefox OS / B2G。我知道可以从壁纸库中获取图像的广泛的API集,更改设置和设置提醒(要为几个)。但是,我完全困难了如何如何更改壁纸,或者,确实如此。道歉,如果这是一个愚蠢的问题。非常感谢。

有帮助吗?

解决方案

您可以使用共享活动来执行此操作

// 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样板测试一个Live示例 https:// github。COM / ROBLYAMAN / FIREFOX-OS-BOULERPLATE-APP /

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top