0
votes

I have to pin secondary tile in my windows phone 8.1 application.

I followed the msdn tutorial : http://code.msdn.microsoft.com/windowsapps/secondary-tiles-sample-edf2a178/

It does work with internal image (ms-appx://.. ) but not with web url (http://)

working sample:

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);
        }
    });
});

And if I use

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

I got an invalid parameter exception.

2

2 Answers

1
votes

You can take a look at the documentation for the SecondaryTile.Logo property. In it you'll see this:

The location of the image. This can be expressed as one of these schemes:

  • ms-appx:///
  • ms-appdata:///local/

You can download the image first and then set it using the ms-appdata:///local/ scheme. I'm not sure that changing the logo with something from the Internet is a good idea, though. This should be the app's logo, so it should be in the package.

1
votes

I found the solution

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);
        ....

I need to download the image, store it and then I can use ms-appdata:///Local