Screen unlocking and lighting

Source: Internet
Author: User

Import Android. App. keyguardmanager;
Import Android. App. keyguardmanager. keyguardlock;
Import Android. App. Service;
Import Android. content. context;
Import Android. content. intent;
Import Android. OS. ibinder;
Import Android. OS. powermanager;
Import Android. util. log;

Public class screenservice extends Service {

// Declare the keyboard Manager
Keyguardmanager mkeyguardmanager = NULL;
// Declare the keyboard lock
Private keyguardlock mkeyguardlock = NULL;
// Declare the Power Manager
Private powermanager PM;
Private powermanager. wakelock;

@ Override
Public ibinder onbind (intent arg0 ){
Return NULL;
}
@ Override
Public void oncreate (){
// Obtain the power of the service
PM = (powermanager) getsystemservice (context. power_service );
// Obtain system services
Mkeyguardmanager = (keyguardmanager) getsystemservice (context. keyguard_service );
Super. oncreate ();
}
@ Override
Public void onstart (intent, int startid ){
// Bright screen
Wakelock = PM. newwakelock (powermanager. acquire_causes_wakeup | powermanager. screen_dim_wake_lock, "my tag ");
Wakelock. Acquire ();
// Initialize the key lock to lock or unlock the key lock
Mkeyguardlock = mkeyguardmanager. newkeyguardlock ("");
// Disable display keyboard lock
Mkeyguardlock. disablekeyguard ();
}
@ Override
Public void ondestroy (){
Wakelock. Release ();
Super. ondestroy ();
}
}

Remember to add it to the androidmanifest file.
<! -- Unlock permission -->
<Uses-Permission Android: Name = "android. Permission. disable_keyguard"> </uses-Permission>
<! -- Screen Display permission -->
<Uses-Permission Android: Name = "android. Permission. wake_lock"> </uses-Permission>

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.