Windows Phone 8 lock screen background and notification 13 features required to upgrade to WP8

Source: Internet
Author: User


Windows Phone 8 supports custom screen lock background images and Application Notification reminders at the bottom of the screen, this is a very eye-catching new feature. Although many applications have already made a feature, I am still here to explain to you how to pave the way for students who want to develop this feature..



This article is an update of 13 feature series required to be updated to WP8. We hope this series will bring some development convenience to Windows Phone 8 developers.



At the same time, you are welcome to communicate with me or @ Wang Bo _ nick on Sina Weibo.



1. screen lock background



As I said, Windows Phone 8 supports screen lock background replacement, which is a source image from msdn.






CodeEasy to write



First, you must declare the XML in the wmappmanifest file after the <tokens> node.

<Extensions>
      <Extension ExtensionName = "LockScreen_Background" ConsumerID = "{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID = "_ default" />
</ Extensions>
 

Modify the lock screen background code

Here I explain "ms-appx: ///" and "ms-appdata: /// Local /"

ms-appdata points to the root of the local app data folder. That is to say, when your picture file is in the file system, use the ms-appdata prefix, which is often used when pictures downloaded from the network are saved in isolated memory Prefix.

ms-appx points to the Local app install folder, to reference resources bundled in the XAP package. When this picture is packaged in the XAP package with the current application, use the ms-appx prefix.

private async void LockHelper (string filePathOfTheImage, bool isAppResource)
{
    try
    {
        var isProvider = Windows.Phone.System.UserProfile.LockScreenManager.IsProvidedByCurrentApplication;
        if (! isProvider)
        {
            // If you're not the provider, this call will prompt the user for permission.
            // Calling RequestAccessAsync from a background agent is not allowed.
            var op = await Windows.Phone.System.UserProfile.LockScreenManager.RequestAccessAsync ();

            // Only do further work if the access was granted.
            isProvider = op == Windows.Phone.System.UserProfile.LockScreenRequestResult.Granted;
        }

        if (isProvider)
        {
            // At this stage, the app is the active lock screen background provider.

            // The following code example shows the new URI schema.
            // ms-appdata points to the root of the local app data folder.
            // ms-appx points to the Local app install folder, to reference resources bundled in the XAP package.
            var schema = isAppResource? "ms-appx: ///": "ms-appdata: /// Local /";
            var uri = new Uri (schema + filePathOfTheImage, UriKind.Absolute);

            // Set the lock screen background image.
            Windows.Phone.System.UserProfile.LockScreen.SetImageUri (uri);

            // Get the URI of the lock screen background image.
            var currentImage = Windows.Phone.System.UserProfile.LockScreen.GetImageUri ();
            System.Diagnostics.Debug.WriteLine ("The new lock screen background image is set to {0}", currentImage.ToString ());
        }
        else
        {
            MessageBox.Show ("You said no, so I can't update your background.");
        }
    }
    catch (System.Exception ex)
    {
        System.Diagnostics.Debug.WriteLine (ex.ToString ());
    }
}
 

After my test execution, here LockScreenManager.RequestAccessAsync () will pop up a user prompt to require user confirmation.

                // Setup lockscreen.
                if (! LockScreenManager.IsProvidedByCurrentApplication)
                {
                    await LockScreenManager.RequestAccessAsync ();
                }
 

When you are updating your lock screen background, especially when reading from a separate storage space, please try to avoid the same file name. I tested the same file name may cause the system default cache and cause the image update delay.

MSDN also provides a way to replace the name

string fileName;
var currentImage = LockScreen.GetImageUri ();

if (currentImage.ToString (). EndsWith ("_ A.jpg"))
{
    fileName = "LiveLockBackground_B.jpg";
}
else
{
    fileName = "LiveLockBackground_A.jpg";
}

var lockImage = string.Format ("{0}", fileName);

// At this point in the code, write the image to isolated storage.
 

Of course, we cannot use code intervention to set the lock screen background before running the program. In our program, we can preset a picture as the lock screen background, but the name of this picture must be DefaultLockScreen.jpg and place this picture in the project root Under contents.

At the same time, on the lock screen settings page, we can see that the button of the open app can directly navigate to our application.The method of handling this navigation is similar to the method of App to App.Overload processing in the App. InitializePhoneApplication method UriMapperBase can be trusted by referring to windows inter-application communication in phone 8

protected override void OnNavigatedTo (System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo (e);

    string lockscreenKey = "WallpaperSettings";
    string lockscreenValue = "0";

    bool lockscreenValueExists = NavigationContext.QueryString.TryGetValue (lockscreenKey, out lockscreenValue);

    if (lockscreenValueExists)
    {
        // Navigate the user to your app's lock screen settings screen here,
        // or indicate that the lock screen background image is updating.
    }
}
 

Of course, in the application, you can also open the settings page through the LaunchUriAsync method. I believe the reference: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662937(v=vs.105).aspx

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

2. Lock screen notification

Windows phone 7 already includes push notifications. In windows phone 8, developers can integrate it into the lock screen interface.

It is also a very clear description of the notification from MSDN. The large characters on the left are the detailed status of the displayed application. The number of notifications for 5 applications can be displayed in the lower line.

Also in the lock screen settings, you can choose to set the application that displays the notification and the application that displays the instant status.

The following describes how the application implements this notification

The first step is to declare in WMAppManifest that our application is an application that supports lock screen notification and specify the icon source of the notification.

The icon must be a PNG image with a transparent 38 x 38 pixels on a white background.

In the Token node

<DeviceLockImageURI IsRelative = "true" IsResource = "false"> Assets \ LockImage.png </ DeviceLockImageURI>
 

Secondly, in the declaration of support notification, the former is to declare support for displaying the application display immediate status, and the latter is to declare the display application displaying detailed status.

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

In fact, it's that simple. As long as your application supports pushing you before, the push information will be displayed on the lock screen after the above settings.

At the same time, everyone is welcome to communicate with me here or on Sina Weibo @ 王博 _Nick

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.