PowerManager pm= (PowerManager) Getsystemservice (Context.power_service);
Get the Power Manager object
Powermanager.wakelock wl = Pm.newwakelock (Powermanager.acquire_causes_wakeup | Powermanager.screen_dim_wake_lock, "bright");
Gets the Powermanager.wakelock object, followed by the argument | To pass in two values at the same time, and finally the tag used in Logcat.
Wl.acquire ();
Light the screen.
Keyguardmanager km= (Keyguardmanager) Getsystemservice (Context.keyguard_service);
Get the keyboard lock manager object
Keyguardlock KL = Km.newkeyguardlock ("UnLock");
parameter is the tag used in Logcat.
Kl.disablekeyguard ();
Unlock
/*
* Other code to write the program here
*
* */
Kl.reenablekeyguard ();
Re-enable auto lock
Wl.release ();
Release
};
I need a broadcast, alas.
Private Devicepolicymanager Policymanager;
Private ComponentName componentname;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
StartService (New Intent (). Setaction ("Lzh00.workservice"));
Finish ();
Policymanager = (Devicepolicymanager) getsystemservice (Context.device_policy_service);
ComponentName = new ComponentName (this, myreceiver.class);
if (policymanager.isadminactive (componentname)) {//To determine if a permission is available (Device Manager activated)
Policymanager.locknow ();//Direct lock screen
Finish ();
} else {
Activemanager ();//Activate Device Manager Get Permissions
Finish ();
}
}
/**
* Get lock Screen permissions
*/
private void Activemanager () {
Activates the specified Device Manager using implicit intent to invoke the system method
Intent Intent = new Intent (devicepolicymanager.action_add_device_admin);
Intent.putextra (Devicepolicymanager.extra_device_admin, componentname);
Intent.putextra (Devicepolicymanager.extra_add_explanation, "one button lock screen");
StartActivity (Intent);
}
Android lit screen with lock screen