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 6964 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);

  }

 }

}

Leave a Comment


x

You might be Interested in these Posts

C Program to find the G.C.D of a number using Recursive function

Problem Write a program in C to find the find the G.C.D of a number using recursion and display the ...

C Program to print a Half Pyramid using *

Problem Write a program in C to print Half pyramid using * as shown. * * * * * * * * * * ...

C Program to display Positive factors of a number

Problem Write a program in C to display all the positive factors of a number enter by the user. Ho...