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/