Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void LockMethod()
- {
- ShakeCount=0;
- Log.d("LUStuff","Lock method called");
- boolean active = devicePolicyManager.isAdminActive(compName);
- if (active) {
- devicePolicyManager.lockNow();
- } else {
- Toast.makeText(getApplicationContext(), "You need to enable the Admin Device Features", Toast.LENGTH_SHORT).show();
- }
- }
- public void UnlockDevice(){
- ShakeCount=0;
- Log.d("LUStuff","UnLock method called");
- KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
- final KeyguardManager.KeyguardLock kl = km .newKeyguardLock("MyKeyguardLock");
- kl.disableKeyguard();
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- @SuppressLint("InvalidWakeLockTag") PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
- | PowerManager.ACQUIRE_CAUSES_WAKEUP
- | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
- wakeLock.acquire();
- }
- @Override
- public void onShakeDetected() {
- ShakeCount+=1;
- KeyguardManager myKM = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
- if( myKM.inKeyguardRestrictedInputMode()) {
- if (ShakeCount==1) {
- UnlockDevice();
- }
- } else {
- if (ShakeCount == 1) {
- LockMethod();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement