Updating Lock Screen from Windows Phone App
By | November 11, 2013

It is sometimes important for an application to change lock screen of the project. The Lock Screen can be set from an app only if the App supports an Extension to change lock screen. Let us take a look on how to change lock screen from an application.

First of all, Lock screen can be changed by an image from three locations :

1. Images located on app folder.
2. Images located on Internet.
3. Images coming from RSS.

The default lock screen size is 480px X 800px or 960px X 1708px.
Here are the steps to allow a program to change the lock screen.

1. In Solution Explorer right click on WMAppManifest.xml and open it with Text Editor.
2. Add lock screen extension to the application, without which the API to change the lock screen will not work.

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

Now to change the lock screen we need the following code.

private async void LockScreenChange(string filePathOfTheImage, bool isAppResource)
{
    if (!LockScreenManager.IsProvidedByCurrentApplication)
    {
        await LockScreenManager.RequestAccessAsync();
   
        var schema = isAppResource ? "ms-appx:///" : "ms-appdata:///Local/";
        var uri = new Uri(schema + filePathOfTheImage, UriKind.Absolute);
 
        LockScreen.SetImageUri(uri);
 

        var currentImage = LockScreen.GetImageUri();
        MessageBox.Show("Lock screen changed. Click F12 or go to lock screen.");
    }
    else
    {
        MessageBox.Show("Background cant be updated as you clicked no!!");
    }
}

Here in the code above, we first try to call LockScreenManager.IsProvidedByCurrentApplication. If this API returns true, the application is then capable of changing lock screen. We then go ahead and RequestAccessAsync on the Change background.

Finally we use LockScreen.SetImageUri with an url pointing to an image with specified resolution to change the lock screen of the Windows Phone environment.
288px AppAsk DL Updating Lock Screen from Windows Phone App
The RequestAccessAsync will present you with a messagebox and upon clicking yes on the confirm, it will change the lock screen. The above screenshot is displayed when RequestAccessAsync is called form code.

The types of URL supported are :

ms-appx:/// for resources bundled within the .xap
ms-appdata:///local/ for local images within the root folder.

Hope this tip helps.

Thank you for reading

3 thoughts on “Updating Lock Screen from Windows Phone App

  1. Pingback: Windows Store App Developer Links – 2013-11-12 | Dan Rigby

  2. Pingback: Opening Settings Screen using Launch URI in Windows Phone | Daily .NET Tips

  3. Pingback: TechNet Blogs

Comments are closed.