天天看點

WP8鎖屏通知(Lock screen notifications for Windows Phone 8)

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:

  1. In Solution Explorer, expand Properties, right-click WMAppManifest.xml, choose Open With, and then select Source Code (Text Editor) With Encoding.
  2. 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.

  1. In Solution Explorer, expand Properties, right-click WMAppManifest.xml, choose Open With, and then select Source Code (Text Editor) With Encoding.
  2. 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" />
   <Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />

</Extensions>
           

3. 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.

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

From:http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207048(v=vs.105).aspx