/** * 激活屏幕,不锁屏。 每次唤醒屏幕前都release。 * * @param context */ public static void acquire(Context context) { DebugLog.v(TAG, "Acquiring wake lock"); if (sWakeLock != null) { sWakeLock.release(); } PowerManager pm = (PowerManager) context .getSystemService(Context.POWER_SERVICE); sWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG); sWakeLock.acquire(); // 解锁 KeyguardManager keyguardManager = (KeyguardManager) context .getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(""); keyguardLock.disableKeyguard(); }
@SuppressWarnings("deprecation") private void riseAndShine(Activity activity) { KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(activity.getLocalClassName()); keyguardLock.disableKeyguard(); activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE); WakeLock lock = powerManager.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "wakeup!"); lock.acquire(); lock.release(); }
@Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { KeyguardManager keyguardManager = (KeyguardManager) context .getSystemService(Activity.KEYGUARD_SERVICE); KeyguardLock lock = keyguardManager .newKeyguardLock(Context.KEYGUARD_SERVICE); lock.disableKeyguard(); Intent myIntent = new Intent(context, BitcoinPosActivity.class); myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(myIntent); } }
static synchronized void secureRelease(Context context, final SecureReleaseCallback callback) { if (keyguardLock != null) { final KeyguardLock finalKeyguardLock = keyguardLock; keyguardLock = null; Log.d(EmailPopup.LOG_TAG, "Keyguard released"); getKeyguardManager(context).exitKeyguardSecurely(new android.app.KeyguardManager.OnKeyguardExitResult() { @Override public void onKeyguardExitResult(boolean success) { Log.d(EmailPopup.LOG_TAG, "onKeyguardExitResult: " + success); //Not sure why we need to reenable keyguard //but it is needed for subsequent keyguard unlock to work properly finalKeyguardLock.reenableKeyguard(); if (success) { callback.onKeyguardSecuredReleased(); } } }); } else { callback.onKeyguardSecuredReleased(); } }
@Override public void onReceive(Context ctx, Intent intent) { //Unlock device screen PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); wl.acquire(30*1000); mKeyGuardManager = (KeyguardManager) ctx.getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("com.inostudio.alar_clock"); mLock.disableKeyguard(); //Create notification creatNotification(ctx); //Start dialog Intent dialog = new Intent(); dialog.setClassName("com.inostudio.alarm_clock", "com.inostudio.alarm_clock.RootActivity"); dialog.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(dialog); //release screen wl.release(); }
/** * 取消锁屏限制 * * @param activity you know */ private static void cancelLockScreen(Activity activity) { Boolean isUnlock = mIsUnlockArray.get(activity); if (isUnlock != null && isUnlock) { return; } KeyguardManager mKeyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock mKeyguardLock = mKeyguardManager.newKeyguardLock(activity.getClass().getName()); mKeyguardLock.disableKeyguard(); mIsUnlockArray.put(activity, true); }
public static void noSysLocker(Context context) { KeyguardManager keyguardManager = (KeyguardManager) context .getApplicationContext().getSystemService( Context.KEYGUARD_SERVICE); KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("Zhaome"); keyguardLock.disableKeyguard(); }
public static void haveSysLocker(Context context) { KeyguardManager keyguardManager = (KeyguardManager) context .getApplicationContext().getSystemService( Context.KEYGUARD_SERVICE); KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("Zhaome"); keyguardLock.reenableKeyguard(); }
public void enable() { KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); lock.disableKeyguard(); startService(new Intent(this, LockScreenService.class)); Toast.makeText(this.getBaseContext(),"Enabled",Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Please set LockScreen as default launcher", Toast.LENGTH_SHORT).show(); }
/** * Not used any more. This is replaced by {@link #initWindowFlags}. * */ @Deprecated private void unlockScreen() { CustomLog.d("Trying to unlock screen..."); KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE); KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); lock.disableKeyguard(); }
private static KeyguardLock getKeyguardLock(Context context) { if (mKeyguardLock == null) { KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Activity.KEYGUARD_SERVICE); mKeyguardLock = keyguardManager.newKeyguardLock("nfcunlocker"); } return mKeyguardLock; }
public static KeyguardLock getMyLock() { return lock; }
@Override public void onSensorChanged(SensorEvent evt) { if(evt.sensor.getType()==Sensor.TYPE_ACCELEROMETER){ //assign directions float x = evt.values[0]; float y = evt.values[1]; float z = evt.values[2]; if(!initializated){ prev_x = x; prev_y = y; prev_z = z; initializated = true; }else{ //The calculation of the error float dx = Math.abs(prev_x - x); float dy = Math.abs(prev_y - y); float dz = Math.abs(prev_z - z); //if error < accuracy set value 0 if(dx < accuracy) dx = 0; if(dy < accuracy) dy = 0; if(dz < accuracy) dz = 0; prev_x = x; prev_y = y; prev_z = z; if(dx > 0 || dy > 0 || dz > 0){ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "com.inostudio.alar_clock"); wl.acquire(30 * 1000); //unlock screen mKeyGuardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("com.inostudio.alar_clock"); mLock.disableKeyguard(); //Start NightActivity Intent nightActivity = new Intent(); nightActivity.setClassName("com.inostudio.alarm_clock", "com.inostudio.alarm_clock.RootActivity"); nightActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(nightActivity); } } } }