Mike Francis: My Mobile Home

Development with Windows Phone, Windows Azure, and Windows 8

WP8: Lock Screen Notifications Sample

 

lock1

Having your app update the lock screen is one of the cool features of Windows Phone 8. It’s pretty easy to add this functionality to your app. See the documentation here for the details. I wrote sample code which you can download here.

The following are a couple of interesting things I found when putting together this sample:

To invoke the emulator’s lock screen press F12. Then press any button. The emulator will then be locked.

 

 

 

 

 

You can also invoke the lock screen via the new and cool ‘Simulation Dashboard’. Click on the ‘Locked’ radio button to lock the emulator. (see below)

image

The docs say the following ‘The lock screen’s app icon, count, and text are pulled directly from the app’s primary Tile.’ I found that the lock screen does not use the app icon from your primary tile. Instead it uses the a separate 38×38 image in your app, specifically for the lock screen, specified in the manifest file.

 

 

 

 

 

 

 

 

 

To have the lock screen update, you need to go to the device settings and enable it. The sample includes a button which will take you directly to the settings page for the lock screen. (Using the new WP8 API LaunchUriAsync.)

settings

In the lock screen settings, select your app’s lock screen icon in the ‘Choose apps to show quick status’ control and specify your app in the ‘Chose app to show detailed status’ drop down. Unless you do this you will not see the lock screen update. (see to the left)

 

 

 

 

 

 

 

The lock screen uses the .BackContent and .Count properties of the main tile StandardTileData to display status and count. To update the main tile:

void UpdateTile(DateTime time)
{
    ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();
    var data = new StandardTileData();
    data.Count = time.Second;
    data.BackContent = string.Format(time.Second.ToString() + " seconds have elapsed.");
    tile.Update(data);
}

Mike

  • http://twitter.com/bang1000 bjørn kaas

    hi… do you know any examples in the marketplace?

  • mjfusa

    Hi Bjørn – Facebook is one WP8 app that supports lock screen notifications.
    Mike

  • Shida

    Where do I find in the appManifest option to set the 30×30 icon? I see only the “App icon” (which set to my colorized app icon) and the tile images.

  • mjfusa

    The icon is actually 38×38. See here for details on how to specify this in the manifest: http://msdn.microsoft.com/en-US/library/windowsphone/develop/jj207048(v=vs.105).aspx
    Mike

Switch to our mobile site