Bard's Tile V : Lock Screen Tiles and Badges

Tags: .NET, Windows 8, WinRT, Tiles, Lock Screen

Bard’s Tile I : Introduction and local Tiles and Badges

Bard’s Tile II : Scheduled and Periodic Notifications

Bard’s Tile III : Push Notifications

Bard’s Tile IV : Secondary Tiles

Bard’s Tile V : Lock Screen Tiles and Badges

Introduction

Not much code for this last part of the Bard’s Tile series. The reason is...well...Windows reroute automatically all badge, tile or toast notifications to the lock screen, if the application is there.

So the most difficult is to make your application lock screen capable.

Lock Screen Badge

To add Lock Screen Badge capability, go to your application manifest and add a badge logo (The icon that will appears on the lock screen) and set the Lock Screen Notifications to Badge, or Badge and Tile Text.

Then, you must add BackgroundTask capabilities in the Declaration tab. Any backgroundtask is ok. You don’t need to implement one, just adding the capability in the manifest is enough. The reason is that, I guess, when the lock screen is on, apps will be suspended eventually. So, if no background tasks, apps will not be updated. So no need to show info on lock screen.

For instance :

Now, you can go to the Windows Preferences and add your app to the lock screen :

Now, any badge notification, number or glyph, will be shown on the lock screen :

Lock Screen Tile

You can also add one tile on the lock screen. It is simply the same tile as your application tile, except it shows only the text.

For that, you must set in the manifest the Lock Screen Notifications to Badge and Tile Text, and add a wide tile to your application. I am not 100% sure why you need a wide tile. My guess is they consider that if you don’t have wide tile, you will not send wide tile updates. Which seems logic. As it is those wide updates that are shown, it would be useless to let an application with only square tile update on the lock screen tile.

Now, you can add your app on the lock screen tile :

Add programmatically to lock screen

You can programmatically add your app to the lock screen :

private async Task RequestAppLockScreen()
{
    var result = await Windows.ApplicationModel.Background.BackgroundExecutionManager.RequestAccessAsync();

    switch (result)
    {
        case Windows.ApplicationModel.Background.BackgroundAccessStatus.Denied:
            //denied;
            break;
        case Windows.ApplicationModel.Background.BackgroundAccessStatus.AllowedWithoutRealTimeConnectivity:
            //added to lock screen;
            break;
        case Windows.ApplicationModel.Background.BackgroundAccessStatus.AllowedWithRealTimeConnectivity:
            //added to lock screen;
            break;
        case Windows.ApplicationModel.Background.BackgroundAccessStatus.Unspecified:
            //unspecified;
            break;
    }
}

 

It will show the confirmation flyout :

It only shows the flyout if app has lock screen capabilities, and is not already on it.

Lock Screen Status

You can also check if your app is on the lock screen :

private void CheckAppLockScreen()
{
    var result = Windows.ApplicationModel.Background.BackgroundExecutionManager.GetAccessStatus();

    switch (result)
    {
        case Windows.ApplicationModel.Background.BackgroundAccessStatus.Denied:
            //denied;
            break;
        case Windows.ApplicationModel.Background.BackgroundAccessStatus.AllowedWithoutRealTimeConnectivity:
            //added to lock screen;
            break;
        case Windows.ApplicationModel.Background.BackgroundAccessStatus.AllowedWithRealTimeConnectivity:
            //added to lock screen;
            break;
        case Windows.ApplicationModel.Background.BackgroundAccessStatus.Unspecified:
            //unspecified;
            break;
    }
}

 

Conclusion

This post concludes the series. I hope I gave a good overview of the tiles. Still many exciting things to blog, stay tuned !

Comments powered by Disqus