문제

나는 최근 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 Boilerplate https : // github를 사용하여 라이브 예제를 테스트 할 수 있습니다.COM / Robnyman / Firefox-OS-Boilerplate-app / .

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top