Java Code Examples for android.app.KeyguardManager#KeyguardLock

The following examples show how to use android.app.KeyguardManager#KeyguardLock . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyAccessibility.java    From MiHomePlus with MIT License 6 votes vote down vote up
private void wakeAndUnlock(boolean b) {
    if (b) {
        //获取电源管理器对象
        powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
        wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);

        // 屏幕解锁
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");

        keyguardLock.reenableKeyguard();
        keyguardLock.disableKeyguard(); // 解锁

        //点亮屏幕
        wakeLock.acquire();
    } else {
        //释放wakeLock,关灯
        wakeLock.release();
    }
}
 
Example 2
Source File: WXClient.java    From Anti-recall with GNU Affero General Public License v3.0 6 votes vote down vote up
public void wakeUpAndUnlock() {
    // TODO: 24/05/2018 解锁密码
    // 获取电源管理器对象
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (pm == null)
        return;
    boolean screenOn = pm.isScreenOn();
    if (!screenOn) {
        // 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
        PowerManager.WakeLock wl = pm.newWakeLock(
                PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
        wl.acquire(1000); // 点亮屏幕
        wl.release(); // 释放
    }
    // 屏幕解锁
    KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");
    // 屏幕锁定
    keyguardLock.reenableKeyguard();
    keyguardLock.disableKeyguard(); // 解锁
}
 
Example 3
Source File: LockScreenService.java    From Simple-Lockscreen with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void onCreate() {
    KeyguardManager.KeyguardLock key;
    KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);

    //This is deprecated, but it is a simple way to disable the lockscreen in code
    key = km.newKeyguardLock("IN");

    key.disableKeyguard();

    //Start listening for the Screen On, Screen Off, and Boot completed actions
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_BOOT_COMPLETED);

    //Set up a receiver to listen for the Intents in this Service
    receiver = new LockScreenReceiver();
    registerReceiver(receiver, filter);

    super.onCreate();
}
 
Example 4
Source File: AlarmActivity.java    From Jide-Note with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    setContentView(R.layout.activity_alarm);

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);// 淡化status bar 和 navigation bar

    // 突破锁屏
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("");
    keyguardLock.disableKeyguard();

    initWidget();

    initData();

}
 
Example 5
Source File: MD5_jni.java    From stynico with MIT License 5 votes vote down vote up
private void wakeUpAndUnlock(Context context)
{
	KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
	KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
	// 解锁
	kl.disableKeyguard();
	// 获取电源管理器对象
	PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
	// 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
	PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
	// 点亮屏幕
	wl.acquire();
	// 释放
	wl.release();
}
 
Example 6
Source File: PowerHelper.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@SuppressLint({"MissingPermission", "WakelockTimeout"})
public static void wake(final Activity activity, final boolean disableKeyguard, final long lockDelayed) {
	try {
		// スリープ状態から起床(android.permission.WAKE_LOCKが必要)
		final PowerManager.WakeLock wakelock
			= ContextUtils.requireSystemService(activity, PowerManager.class)
				.newWakeLock(PowerManager.FULL_WAKE_LOCK
					| PowerManager.ACQUIRE_CAUSES_WAKEUP
					| PowerManager.ON_AFTER_RELEASE, "PowerHelper:disableLock");
		if (lockDelayed > 0) {
			wakelock.acquire(lockDelayed);
		} else {
			wakelock.acquire();
		}
		// キーガードを解除(android.permission.DISABLE_KEYGUARDが必要)
		try {
			final KeyguardManager keyguard = ContextUtils.requireSystemService(activity, KeyguardManager.class);
			final KeyguardManager.KeyguardLock keylock = keyguard.newKeyguardLock(TAG);
			keylock.disableKeyguard();
		} finally {
			wakelock.release();
		}
		// 画面がOFFにならないようにする
		activity.getWindow().addFlags(
			WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	} catch (final Exception e) {
		Log.w(TAG, e);
	}
}
 
Example 7
Source File: AlarmReciver.java    From Moring-Alarm with Apache License 2.0 5 votes vote down vote up
private void wakePhoneAndUnlock() {
        PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "WakeLock");
        mWakelock.acquire();//唤醒屏幕
//......
        KeyguardManager mManager = (KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE);
        KeyguardManager.KeyguardLock mKeyguardLock = mManager.newKeyguardLock("Lock");
//让键盘锁失效
        mKeyguardLock.disableKeyguard();
        mWakelock.release();//释放
    }
 
Example 8
Source File: ExampleInstrumentedTest.java    From za-Farmer with MIT License 5 votes vote down vote up
@Before
public void setUp() throws RemoteException {
    mUIDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());  //获得device对象
    mContext = InstrumentationRegistry.getContext();
    KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock kl = km.newKeyguardLock("farmer");
    //解锁
    kl.disableKeyguard();
    if (!mUIDevice.isScreenOn()) {
        mUIDevice.wakeUp();
    }

}
 
Example 9
Source File: MonitorService.java    From luckymoney with Apache License 2.0 5 votes vote down vote up
private void unlockScreen() {
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    final KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("MyKeyguardLock");
    keyguardLock.disableKeyguard();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");

    wakeLock.acquire();
}
 
Example 10
Source File: WatchServices.java    From WearPay with GNU General Public License v2.0 5 votes vote down vote up
public static void wakeUpAndUnlock(Context context){
    KeyguardManager km= (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
    //解锁
    kl.disableKeyguard();
    //获取电源管理器对象
    PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE);
    //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"bright");
    //点亮屏幕
    wl.acquire();
    //释放
    wl.release();
}
 
Example 11
Source File: OwrActivityTestCase.java    From openwebrtc-android-sdk with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mTextureView = new TextureView(this);
    setContentView(mTextureView);
    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock keyguardLock = km.newKeyguardLock("TAG");
    keyguardLock.disableKeyguard();
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
 
Example 12
Source File: KeyguardLock.java    From AndroidBase with Apache License 2.0 4 votes vote down vote up
public void setKeyguardLock(KeyguardManager.KeyguardLock keyguardLock) {
    this.keyguardLock = keyguardLock;
}
 
Example 13
Source File: KeyguardLock.java    From android-common with Apache License 2.0 4 votes vote down vote up
public void setKeyguardLock(KeyguardManager.KeyguardLock keyguardLock) {
    this.keyguardLock = keyguardLock;
}
 
Example 14
Source File: KeyguardLock.java    From android-common with Apache License 2.0 4 votes vote down vote up
public KeyguardManager.KeyguardLock getKeyguardLock() {
    return keyguardLock;
}
 
Example 15
Source File: ApplicationUtil.java    From RxAndroidBootstrap with Apache License 2.0 4 votes vote down vote up
/**
 * Release the devices screen lock.
 * @param context
 */
public static void releaseScreenLock(Context context){
    KeyguardManager keyguardManager = (KeyguardManager) context.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock keyguardLock =  keyguardManager.newKeyguardLock("TAG");
    keyguardLock.disableKeyguard();
}
 
Example 16
Source File: ApplicationUtil.java    From MVPAndroidBootstrap with Apache License 2.0 4 votes vote down vote up
/**
 * Release the devices screen lock.
 * @param context
 */
public static void releaseScreenLock(Context context){
    KeyguardManager keyguardManager = (KeyguardManager) context.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock keyguardLock =  keyguardManager.newKeyguardLock("TAG");
    keyguardLock.disableKeyguard();
}
 
Example 17
Source File: KeyguardLock.java    From AndroidBase with Apache License 2.0 4 votes vote down vote up
public KeyguardManager.KeyguardLock getKeyguardLock() {
    return keyguardLock;
}
 
Example 18
Source File: KeyguardUtils.java    From DevUtils with Apache License 2.0 2 votes vote down vote up
/**
 * 设置 KeyguardManager.KeyguardLock
 * @param keyguardLock {@link KeyguardManager.KeyguardLock}
 * @return {@link KeyguardUtils}
 */
public KeyguardUtils setKeyguardLock(final KeyguardManager.KeyguardLock keyguardLock) {
    this.mKeyguardLock = keyguardLock;
    return this;
}
 
Example 19
Source File: KeyguardUtils.java    From DevUtils with Apache License 2.0 2 votes vote down vote up
/**
 * 获取 KeyguardManager.KeyguardLock
 * @return {@link KeyguardManager.KeyguardLock}
 */
public KeyguardManager.KeyguardLock getKeyguardLock() {
    return mKeyguardLock;
}