次要瓷砖网址

时间:2014-05-28 07:00:32

标签: winjs windows-phone-8.1

我必须在我的Windows Phone 8.1应用程序中固定辅助磁贴。

我按照msdn教程:http://code.msdn.microsoft.com/windowsapps/secondary-tiles-sample-edf2a178/

它适用于内部图像(ms-appx:// ..)但不适用于网址(http://)

工作样本:

var logo = new Windows.Foundation.Uri("ms-appx:///Images/square30x30Tile-sdk.png"); 
var currentTime = new Date();
var TileActivationArguments = data.ad_id + " WasPinnedAt=" + currentTime;



var tile = new Windows.UI.StartScreen.SecondaryTile(data.ad_id,
data.subject,
TileActivationArguments,
logo,
Windows.UI.StartScreen.TileSize.square150x150);
tile.visualElements.foregroundText = Windows.UI.StartScreen.ForegroundText.light;
tile.visualElements.square30x30Logo = logo;
tile.visualElements.showNameOnSquare150x150Logo = true;



var selectionRect = this.element.getBoundingClientRect();

// Now let's try to pin the tile. 
// We'll make the same fundamental call as we did in pinByElement, but this time we'll return a promise. 
return new WinJS.Promise(function (complete, error, progress) {
    tile.requestCreateForSelectionAsync({ x: selectionRect.left, y: selectionRect.top, width: selectionRect.width, height: selectionRect.height }, Windows.UI.Popups.Placement.above).done(function (isCreated) {
        if (isCreated) {
            complete(true);
        } else {
            complete(false);
        }
    });
});

如果我使用

var logo = new Windows.Foundation.Uri(data.images[0]);

我收到了无效的参数异常。

2 个答案:

答案 0 :(得分:1)

您可以查看SecondaryTile.Logo属性的文档。在其中你会看到:

  

图像的位置。这可以表示为以下方案之一:

     
      
  • MS-APPX:///
  •   
  • MS-应用程序数据:///本地/
  •   

您可以先下载图像,然后使用ms-appdata:/// local / scheme进行设置。不过,我不确定用互联网上的东西改变标识是个好主意。这应该是应用程序的徽标,因此它应该在包中。

答案 1 :(得分:1)

我找到了解决方案

fileExists: function (fileName) {
var applicationData = Windows.Storage.ApplicationData.current;
var folder = applicationData.localFolder;
return folder.getFileAsync(fileName).then(function (file) {
    return file;
}, function (err) {
    return null;
});
},
download: function (imgUrl, imgName) {
return WinJS.xhr({ url: imgUrl, responseType: "blob" }).then(function (result) {
    var blob = result.response;
    var applicationData = Windows.Storage.ApplicationData.current;
    var folder = applicationData.localFolder;
    return folder.createFileAsync(imgName, Windows.Storage.
           CreationCollisionOption.replaceExisting).then(function (file) {
               // Open the returned file in order to copy the data
               return file.openAsync(Windows.Storage.FileAccessMode.readWrite).
                                                     then(function (stream) {
                                                         return Windows.Storage.Streams.RandomAccessStream.copyAsync
                                                                (blob.msDetachStream(), stream).then(function () {
                                                                    // Copy the stream from the blob to the File stream
                                                                    return stream.flushAsync().then(function () {
                                                                        stream.close();
                                                                    });
                                                                });
                                                     });
           });
}, function (e) {
    //var msg = new Windows.UI.Popups.MessageDialog(e.message);
    //msg.showAsync();
});
},

var self = this;
this.download(data.images[0], data.ad_id).then(function () {
    self.fileExists(data.ad_id).then(function (file) {
        var logo = new Windows.Foundation.Uri("ms-appdata:///Local/" + data.ad_id);
        ....

我需要下载图片,存储它,然后我可以使用 ms-appdata:/// Local