Make a picture in your wp8 app your lock screen background

If you want to make an image within you application as your lock screen image, you just need to follow these simple steps. For eg. , you have an album app where you have your pictures stored and you want to make one of those as your lockscreen background. So, instead of saving your picture and going to setting to set it as background, just click a button and have it there! Enable this feature in your apps by following:

1. Create a project and add an image to the page that you want to make the lock screen background. (Your photo or any image already added to the project works).  minion12. In the MainPage.xaml.cs (or any other xaml file you are working on), uncomment the ‘BuildLocalizedApplicationBar()’ in the constructor. Also uncomment the method implementation down in the same page.

3. Open the AppResources.resx page in Resources in the solution explorer.

4. Replace the appbarButtonText by AppBarLockScreen and replace the text beside it by LockScreenImage

minion2

5. Replace the application bar button code by this: (The image (save.png) is the one to be shown on app bar button

ApplicationBarIconButton appBarButton = new  ApplicationBarIconButton   (new Uri(“/Assets/Images/save.png”, UriKind.Relative));

appBarButton.Text = AppResources.AppBarLockscreenImage;

ApplicationBar.Buttons.Add(appBarButton);

6. Comment out or remove the app bar menu item code.

7. Then add an event to appBarButton by typing appBarButton+= (press TAB twice) to generate the method stub also.

8. In the event handler for appBarButton, replace it by following code:

minion4

9. Add using Windows.Phone.System.UserProfile; at the top.

10. Now the code is ready but you need to add an extension to the app to enable the app to be recognized as lock screen background provider. For this, right click on the WMAppManifest and click on ‘Open with’. Select ‘XML (Text) Editor’. Add the following code under <tokens> tag:

<Extensions>

<Extension

ExtensionName=”LockScreen_Background”

ConsumerID=”DFF24-AA15-4A96-8006-2BFF8122084F}”

TaskID=”_default” />

</Extensions>

Don’t add the <Extensions> start and end tag in this code if already present there.

11. Now run the application. And to lock the screen, first open the simulation dashboard from tools->Simulation Dashboard.

minion3

12. Now click on the button in the app bar. It prompts the user to confirm to make the
picture the lock screen background.

minion 5

13. Click ok and select locked under lock screen in simulation dashboard. Look in the emulator and your picture is the lock screen background!

minion 6

5 Comments

    • Can you please elaborate what do you mean by allowing user to select images from ‘image folders’?

      • When a user opens his lock screen app, he should be able to choose an image as his lock screen image from the images available in his phone. Lets say I have 50 images in my phone.When I open my lock screen app, there should be an option to choose an image. It should let me browse through my phone to select an image as my lock screen image.

Leave a comment