How to Prevent the Lock Screen to automatically lock from the Windows Phone 8 App?

Published on November 9, 2013 by abundantcode

Filed under Windows Phone

Last modified November 9, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3769 times

There are times when the automatic lock of the Screen is enabled by the user in the Settings App of the Windows Phone 8. When your App is running on the device, sometimes you may not want to lock the device automatically for various reasons .

How to Prevent the Lock Screen to automatically lock from the Windows Phone 8 App?

Below is a sample code snippet demonstrating how to prevent the system timeout or prevent the Lock Screen to automatically lock from the Windows Phone 8 App.

using Microsoft.Phone.Controls;

using Microsoft.Phone.Tasks;

using System;

using System.Collections.Generic;

using System.Collections.ObjectModel;

using System.Linq;

using System.Windows;

using System.Windows.Controls;

using Windows.Phone.Speech.Recognition;

using Windows.System;

namespace AbundantCodeWP8

{

 public partial class MainPage : PhoneApplicationPage

 {

  public MainPage()

  {

   InitializeComponent();

  }

  public void PreventLockScreen(bool value)

  {

   if (value)

    Microsoft.Phone.Shell.PhoneApplicationService.Current.UserIdleDetectionMode = Microsoft.Phone.Shell.IdleDetectionMode.Disabled;

   else

    Microsoft.Phone.Shell.PhoneApplicationService.Current.UserIdleDetectionMode = Microsoft.Phone.Shell.IdleDetectionMode.Enabled;

  }

  private void Button_Click_1(object sender, RoutedEventArgs e)

  {

   PreventLockScreen(true);

  }

 }

}
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to hide horizontal or vertical scroll bar using VBA Code in Excel ?

Here's a VBA code that hides the horizontal and vertical scroll bar in Microsoft Excel. How to hide...

Deleting all the hidden rows and columns in the active worksheet using VBA

Do you want to delete all the hidden rows and columns in the active worksheet in Microsoft Excel usi...

Displaying all the worksheet names in Excel using VBA Code

Do you want to display the names of the worksheets in the excel workbook ?. Here;s how you can do it...