What’s New in Windows Phone 8 (2 out of 8)–Lock Screen

October 31, 2012

In previous post I described how to enrich user experience by customizing application tiles. In this post I will show how to enable your application to present some information on phone’s lock screen.

In Windows Phone 8 applications could provide 3 pieces of info on lock screen: application’s icon, count and text. On screenshot below my sample application provides icon, count and some text:

image

If application selected by user, the lock screen could show app icon defined in app manifest, count and text pulled directly from the application’s primary tile. The secondary tiles does not have an impact on lock screen.

Let’s see how to achieve it. First of all – icon presented on lock screen must be 24×24 transparent PNG image with white pixels (plus transparent pixels obviously). Once such image created, add it to the application and then open application manifest using XML editor as follows (right click on manifest file and select “Open With…”:

image

Then select XML (Text) Editor:

image

Locate “DeviceLockImageURI” element (within PrimaryToken/Template definition) and specify path to the image:

<DeviceLockImageURI IsRelative="true" IsResource="false">Images\lock_icon.png</DeviceLockImageURI>

To enable application icon and count add new Extensions element and new Extension as follows:

<Extensions>

  <Extension ExtensionName="LockScreen_Notification_IconCount" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />

</Extensions>

Note:Extension element must be next to Tokens element.

If you plan to provide lock screen with text updates, add the following Extension element to the Extensions section:

<Extension ExtensionName="LockScreen_Notification_TextField" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />

Note:Your application could use multiple extension elements, but consider providing only those, which are really used by the application.

Also note: As the text pulled directly from the application’s primary tile, cyclic tile template shouldn’t be used with LockScreen_Notification_TextField extension as it has no text.

Once application with extensions in manifest deployed to device, user can select the application in Settings/Lock Screen section – application name will be available for selection at notifications sections (detailed and quick status):

image

Note: the settings should be done by user from Settings menu and cannot be defined form code.

Lock screen Background

In addition to information presented above, Windows Phone 8 application could be then chosen lock screen background provider application, so that application can provide the lock screen background.

To enable this functionality your application must declare additional Extension in application manifest (could be used with or without other lock screen extensions):

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

Once defined (after deployment) user will be able to choose your application form list of the applications with same functionality on the device:

imageimageimage

In addition to this manual method the default lock screen provide could also be changed from code. Let’s see how to request provide lock screen background from code:

//Check if application already lock screen background provider

if (!LockScreenManager.IsProvidedByCurrentApplication)

{

    //No, request to be active lockscreen wallpaper provider

    var res = await LockScreenManager.RequestAccessAsync();

 

    if (res == LockScreenRequestResult.Granted)

    {

        //Request approved

        //...

    }

    else

    {

        //Request rejected

        //...

    }

}

The code snippet checks if lock screen already provided by current application, and if not raises request. This request is raised to user as following message box (system provided):

image

User approval equivalent to Settings change.

Note: user can change this at any time using Settings screen, thus before setting actual background the app should change it it is still current provider.

Now, let’s see how to set lock screen background:

if (LockScreenManager.IsProvidedByCurrentApplication)

{

    string fileName = "ms-appx:///Images/WP1.JPG";

 

    Uri uri = new Uri(fileName, UriKind.RelativeOrAbsolute);

    LockScreen.SetImageUri(uri);

 

    //Lock screen background set

    //...

}

This code snippet verifies that application is still active lock screen background provider and invokes LockScreen.SetImageUri function which changes the background.

In addition, the LockScreen class provides access to current background image URI by LockScreen.GetImageUri function.

 

Simulation Dashboard

New version of Windows Phone Emulator and SDK provides new tool called Simulation Dashboard which enables simulation of various network conditions, lock screen and reminders. This tool located in Tools menu in Visual Studio:

image

image

Use radio buttons in Lock Screen section to simulate locking the screen on emulator.

image

 

That’s it for now. Next time I will show how to integrate voice recognition into your application.

 

Stay tuned,

Alex

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

one comment

  1. PHenryNovember 1, 2012 ב 17:16

    Is there only allowed to be one app which can change the lock screen? If yes, I have to question the effort involved for something a user may WANT to use, but may decide not to cause they have another.

    Reply