EgorBo
EgorBo

Reputation: 6142

Update secondary tile via push notification

I pinned a secondary tile using this code:

string secondaryTileId = "1";

var tile = new SecondaryTile(secondaryTileId, "Short name", "Display name", 
    "ActivationArgument", TileOptions.ShowNameOnLogo, photoUri);
var result = await tile.RequestCreateForSelectionAsync(...);

Can I update only this secondary tile via push notification (from my back-end)? If yes - where should I put this ID in this xml?:

<?xml version='1.0' encoding='utf-8'?>
<tile>
    <visual lang="en-US">
        <binding template="TileSquarePeekImageAndText02">
            <image id="1" src="{0}"/>
            <text id="1">{1}</text>
            <text id="2">{2}</text>
        </binding>
    </visual>
</tile>

I tried to add attribute Id="1" or TileId="1" for tile node but with no luck (it updates only primary tile)

Upvotes: 1

Views: 590

Answers (1)

Push notifications are always sent through a channel URI and each channel URI is tied to a specific tile+user+device. So if you're sending to the channel URI for the primary tile (from PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync, in Windows.Networking.PushNotifications), that notification will always end up on that tile. There is an exception to this I'll explain in a moment.

Typically, for a secondary tile, you obtain its own channel through the [CreatePushNotificationChannelForSecondaryTileAsync][2] API instead. You'll need to send this channel's URI to your service the same way you send the one for the primary tile.

However, if you want to receive and process push notifications directly, then you can use the primary tile channel for that purpose. That is, the "ChannelForApplication" channel is used for the primary tile, toasts, and raw notifications alike, so its link to the primary tile is just part of its use. Anyway, to handle the notifications, you subscribe to the Channel object's PushNotificationReceived event, in which you can intercept the notification, check for any custom tags you want to put in there, and route it to a secondary tile if you want.

Of course, that only works for a running app. To do it when you're not running requires a background task with a PushNotificationTrigger, where you'll basically do the same time.

Upvotes: 2

Related Questions