Android programming to prohibit system lock screen and Jianjiang screen method _android

Source: Internet
Author: User

This article describes the Android programming to prohibit the system lock screen and Jianjiang screen method. Share to everyone for your reference, specific as follows:

Demand:

At some point, the task finishes, closes the screen, opens the screen at some point, continues to perform the task

Usually, do not set the screen often bright, the system will automatically lock the screen, lock screen can not unlock from the code (doubt), so my practice is only to let the system close the screen, but not the screen!

Wakelock lock, UnLock;
Keyguardmanager km;
Keyguardlock KL;

UnLock = Pm.newwakelock (Powermanager.acquire_causes_wakeup | Powermanager.screen_bright_wake_lock, "BRIGHT");
Get keyboard lock Manager Object
km = (keyguardmanager) getsystemservice (context.keyguard_service);
KL = Km.newkeyguardlock ("UnLock");

void Lockscreen () {
  //Lock screen
  kl.reenablekeyguard ();
  Release Wakelock, turn off the light
  if (Unlock.isheld ())
    unlock.release ();
}
void Unlockscreen () {
  //lit screen
  if (!unlock.isheld ())
    unlock.acquire ();
  Unlock
  kl.disablekeyguard ();
}

Test code, call the test code, you manually press the power button to lock the screen, 5s you will see the screen light up

{
  lockscreen ();
  Getlistview (). GetHandler (). postdelayed (New Runnable () {
    @Override public
    void Run () {
      unlockscreen ();
    }
  }, 5000);
  break;


I hope this article will help you with the Android program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.