Android StartService How to start an automatic unlock dot bright screen

Source: Internet
Author: User

See a post, do note, post in: http://topic.csdn.net/u/20110304/15/ae5279b1-692e-48a7-a5b9-0e579a3a6974.html

What I want to record is:

Do a reminder function of a service, automatic unlock + light screen.

Write an activity start the service, use a thread to open the service, if the black screen to start the effect of the state.

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 keyboard manager Keyguardmanager Mkeyguardmanager = null;    
Declare keyboard lock private keyguardlock mkeyguardlock = null;  
Declare the Power Manager private PowerManager pm;  
      
Private Powermanager.wakelock Wakelock;    
@Override public IBinder onbind (Intent arg0) {return null;  
@Override public void OnCreate () {//Get power service PM = (powermanager) getsystemservice (Context.power_service);  
Get system Services Mkeyguardmanager = (Keyguardmanager) getsystemservice (Context.keyguard_service);    
Super.oncreate (); @Override public void OnStart (Intent Intent, int startid) {//dot-bright screen wakelock = Pm.newwakelock (Powermanager.acquir E_causes_wakeup | Powermanager.scrEen_dim_wake_lock, "my Tag");  
Wakelock.acquire ();  
LOG.I ("Log:", "------>mkeyguardlock");    
Initialize keyboard lock, can lock or unlock keyboard lock Mkeyguardlock = Mkeyguardmanager.newkeyguardlock ("");    
Disables the display of keyboard lock Mkeyguardlock.disablekeyguard ();  
@Override public void OnDestroy () {wakelock.release ();  
Super.ondestroy (); }    
}

Remember to include in the Androidmanifest file

<!--unlock Permissions-->

<uses-permission android:name= "Android.permission.DISABLE_KEYGUARD" ></uses-permission>

<!--the permissions--> the screen

<uses-permission android:name= "Android.permission.WAKE_LOCK" ></uses-permission>

Started with StartService, the screen is not completely black, in the activity of the Stop method StopService,

Then the Destory method of the service will release the Mwakelock.release () of the bright screen;

So it won't keep on burning.

Although the screen is bright, but does not like the normal operation that completely lightens ah, this makes the screen to brighten just a little, or very dark.

public void Acquire ()//The method only ensures that the screen is awakened

Makes sure the "device is" on "at" you asked the created lock.

The public void acquire (long timeout)//parameter indicates the time of the wake-up, and the lock is automatically released after the time

Makes sure the "device is" on "at" you asked the created lock. The lock is released after the given timeout.

API has a parameter that can be lit

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

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.