Lock screen notifications for Windows Phone 8
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
The lock screen in Windows Phone OS 7.1 contains a handful of notifications such as the number of new Outlook emails and text messages. In Windows Phone 8, app users can choose to customize this area with any eligible third-party apps they choose. You can design your app to be an app that the phone user can choose to customize the lock screen notifications area.
The lock screen's app icon, count, and text are pulled directly from the app's default Tile. The app's secondary Tile doesn’t affect this feature. Info appears on the lock screen only if the default Tile contains this info. For example, a count will appear on the lock screen only if the Tile displays it.
To make your app eligible to be included in the notifications area, you simply need to declare the app's intent in the app manifest file and create an icon to use to represent your app. Then, you must go to the phone's Settings/lock screen page and add the app as a provider of lock screen notifications, as shown in the following image.
This topic contains the following sections.
- Creating a lock screen icon
- Setting app manifest extensions for the lock screen
- Linking the lock screen settings screen from within your app
- Related Topics
Creating a lock screen icon
Create a 38 x 38 pixel PNG image that will identify your app on the lock screen. The image must contain only white pixels plus some level of transparency.
Update the app manifest file by following these steps:
In Solution Explorer, expand Properties, right-click WMAppManifest.xml, choose Open With, and then select Source Code (Text Editor) With Encoding.
Update the DeviceLockImageURI element inside the Tokens element. Add the full path to your image file, set IsRelative="true" and IsResource="false" as shown in the following code example.
<DeviceLockImageURI IsRelative="true" IsResource="false">Assets\LockImage.png</DeviceLockImageURI>
Setting app manifest extensions for the lock screen
Next, declare what aspects your app will support in the lock screen notifications area by updating the app manifest file.
In Solution Explorer, expand Properties, right-click WMAppManifest.xml, choose Open With, and then select Source Code (Text Editor) With Encoding.
Add the lock screen wallpaper <Extension> element in the <Extensions> element. If the <Extensions> element doesn’t appear in the file, place the entire following code example in the file. The <Extensions> element must be placed below the <Tokens> element.
<Extensions> <Extension ExtensionName="LockScreen_Notification_IconCount" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> <Extension ExtensionName="LockScreen_Notification_TextField" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> </Extensions>
Only include the <Extension> elements that you want to support. If you plan to include your Tile's Count on the lock screen, include the LockScreen_Notification_IconCount extension. If you plan to include text, include the LockScreen_Notification_TextField extension.
When you register your app to be a lock screen notification badge, you can register your app as a Silverlight app or a modern app. If you register your app as both a Silverlight app and a modern app, your app will not be cleared from the list of potential lock apps when a user uninstalls your app. To prevent this from happening, be sure to register your app as only a modern app or a Silverlight app, but not both.
Linking the lock screen settings screen from within your app
Consider adding a link to the phone's lock screen settings screen from within your app for your app user’s benefit. This is useful for the user because you can’t programmatically turn off your app as a lock screen background image provider from within the app. The user will need to visit the phone's settings screen and make the change themselves. Providing a link to the settings screen makes this straightforward and easy.
The following code example shows you how you can route a button click to the phone's lock screen settings screen.
private async void btnGoToLockSettings_Click(object sender, RoutedEventArgs e)
{
// Launch URI for the lock screen settings screen.
var op = await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-lock:"));
}