Windows Phone 8 Lock screen background and notifications

Source: Internet
Author: User

Windows Phone 8 on the lock screen background picture is supported by app customization, and app notification reminders are also supported at the bottom of the screen, a new feature that is very eye-catching Although we have already seen a lot of applications have made a feature today I still believe in this for everyone to explain for the back of the students want to do this function to pave the way first.

This article is an update to the 13 feature series that you must know to upgrade to Windows Phone 8 and hopefully this series will bring some development convenience to Windows Phone 8 developers.

1. Lock Screen Background

As I said, Windows Phone 8 is a replacement for the lock screen background, which is a good understanding of the original image from MSDN

The code is very simple to write.

First, it is declared in the Wmappmanifest file that the XML is immediately behind 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'll explain "ms-appx:///" and "ms-appdata:///local/."

Ms-appdata points to the root of the local app data folder. That is, when your image file is in the file system using the Ms-appdata prefix, the images that are often downloaded from the network are stored in the isolated memory to use this prefix.

Ms-appx points to the Local app install folder, to reference resources bundled in the XAP package. Use the MS-APPX prefix when this picture is packaged with the current app in the XAP package.

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 would prompt the user for permission. Calling Requestaccessasync from a background agent is not allowed.

var op = await

Windows.Phone.System.UserProfile.LockScreenManager.RequestAccessAsync (); Only does further work if the access is granted.

Isprovider = OP = =

Windows.Phone.System.UserProfile.LockScreenRequestResult.Granted;

}

if (Isprovider)

{

At this stage, the app was 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 was set to {0}", currentimage.tostring ());

}

Else

{MessageBox.Show ("said no, so I can ' t update your background."); }    }

catch (System.exceptionex)

{

System.Diagnostics.Debug.WriteLine (ex. ToString ());

}}

After my test execution here Lockscreenmanager.requestaccessasync () will pop up a user prompt requiring user confirmation.

Setup Lockscreen.

If

(! Lockscreenmanager.isprovidedbycurrentapplication)

{await lockscreenmanager.requestaccessasync (); }

When you update your lock screen background, especially when reading from isolated storage, try to avoid the same file name when I test that the same file name may cause the system default cache to cause a delay in picture updates.

MSDN also provides a way to replace names

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 the-this-in-code, write the image to isolated storage.

Of course, before we run the program, we can't use the code to intervene. Setting the lock screen background in our program you can preset a picture as a lock screen background but this image must be named Defaultlockscreen.jpg and put this image in the project root directory.

At the same time on the Lock screen settings page We can see the Open App button can navigate directly to our app to handle this navigation method and the app to app method similar Overloading handles Initializephoneapplication methods in the app Urimapperbase can be trusted to refer to inter-application communication in Windows 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

or indicate the lock screen background image is updating. }}

Of course, in the application can also open the Settings page through the Launchuriasync Method Trust 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 screens settings screen.

var op = await Windows.System.Launcher.LaunchUriAsync (new

Uri ("Ms-settings-lock:"));}

2. Lock screen Notification

Push notifications are already included in Windows Phone 7, and developers can incorporate them into the lock screen in Windows Phone 8

Or a very clear notification from MSDN, the left character is the detailed status of the displayed app, and the following line shows the number of notifications for 5 applications.

Also in the lock screen settings you can choose to set the display notification app and display the instant status of the app.

Below is a description of how the application implements this notification

The first step is to declare in Wmappmanifest that our app is an app that supports lock screen notifications and also specifies the icon source for notifications.

The icon must be a white background transparent x 38 pixel PNG image.

In the token node

<devicelockimageuri

Isrelative= "true" Isresource= "false" >Assets/LockImage.png</DeviceLockImageURI>

Second in the statement support notification the former is a declaration support display app shows the instant status The latter is a claim display app showing 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>

If there's any confusion, there are several similar examples of it online education platforms. But I think you crossing should have been very clear. In fact it is so simple, as long as your app supports pushing you through the above settings push message will be displayed on the lock screen.

Done.

Windows Phone 8 Lock screen background and notifications

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.