Java Code Examples for android.app.KeyguardManager#newKeyguardLock()
The following examples show how to use
android.app.KeyguardManager#newKeyguardLock() .
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: VolumePanel.java From Noyze with Apache License 2.0 | 7 votes |
/** Start an activity. Returns true if successful. */ @SuppressWarnings("deprecation") protected boolean startActivity(Intent intent) { Context context = getContext(); if (null == context || null == intent) return false; // Disable the Keyguard if necessary. KeyguardManager mKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); if (mKM.isKeyguardLocked() && !mKM.isKeyguardSecure()) { mKeyguardLock = mKM.newKeyguardLock(getName()); mKeyguardLock.disableKeyguard(); } try { // Necessary because we're in a background Service! intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); return true; } } catch (ActivityNotFoundException anfe) { LOGE("VolumePanel", "Error launching Intent: " + intent.toString(), anfe); } catch (SecurityException se) { LOGE("VolumePanel", "Error launching Intent: " + intent.toString(), se); Toast.makeText(context, R.string.permission_error, Toast.LENGTH_SHORT).show(); } return false; }
Example 2
Source File: ButlerService.java From test-butler with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); Log.d(TAG, "ButlerService starting up..."); try { shellBinder = new ShellButlerServiceBinder(this); butlerApi = shellBinder.bind(5, TimeUnit.SECONDS); locks = new CommonDeviceLocks(); locks.acquire(this); // CommonDeviceLocks doesn't enable the Keyguard Lock on Q due to compatibility issues. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); keyguardLock = keyguardManager.newKeyguardLock("ButlerKeyguardLock"); keyguardLock.disableKeyguard(); } accessibilityServiceWaiter = new AccessibilityServiceWaiter(); Log.d(TAG, "ButlerService startup completed..."); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
Example 3
Source File: AppCompatDlalog.java From stynico with MIT License | 6 votes |
private void wakeAndUnlock() { //获取电源管理器对象 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright"); //点亮屏幕 wl.acquire(1000); //得到键盘锁管理器对象 KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); kl = km.newKeyguardLock("unLock"); //解锁 kl.disableKeyguard(); }
Example 4
Source File: LockScreenService.java From Simple-Lockscreen with MIT License | 6 votes |
@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 5
Source File: MyAccessibility.java From MiHomePlus with MIT License | 6 votes |
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 6
Source File: OwrActivityTestCase.java From openwebrtc-android-sdk with BSD 2-Clause "Simplified" License | 5 votes |
@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 7
Source File: LockerUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
public static void noSysLocker(Context context) { KeyguardManager keyguardManager = (KeyguardManager) context .getApplicationContext().getSystemService( Context.KEYGUARD_SERVICE); KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("Zhaome"); keyguardLock.disableKeyguard(); }
Example 8
Source File: LockerUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
public static void haveSysLocker(Context context) { KeyguardManager keyguardManager = (KeyguardManager) context .getApplicationContext().getSystemService( Context.KEYGUARD_SERVICE); KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("Zhaome"); keyguardLock.reenableKeyguard(); }
Example 9
Source File: MonitorService.java From luckymoney with Apache License 2.0 | 5 votes |
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: PowerHelper.java From libcommon with Apache License 2.0 | 5 votes |
@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 11
Source File: ScreenLockUtil.java From AndroidModulePattern with Apache License 2.0 | 5 votes |
/** * 取消锁屏限制 * * @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); }
Example 12
Source File: AlarmReciver.java From Moring-Alarm with Apache License 2.0 | 5 votes |
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 13
Source File: PinEntryEditText.java From stynico with MIT License | 5 votes |
@Override public IBinder onBind(Intent intent) { IBinder mIBinder = super.onBind(intent); mBinding = true; powerMan = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerMan.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP, "WakeLock"); keyMan = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); keyLock = keyMan.newKeyguardLock("KeyLock"); // #TODO 换掉这些deprecated方法, return mIBinder; }
Example 14
Source File: Air.java From stynico with MIT License | 5 votes |
private void wakeAndUnlock2(boolean b) { if(b) { //获取电源管理器对象 pm=(PowerManager) getSystemService(Context.POWER_SERVICE); //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright"); //点亮屏幕 wl.acquire(); //得到键盘锁管理器对象 km= (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); kl = km.newKeyguardLock("unLock"); //解锁 kl.disableKeyguard(); } else { //锁屏 kl.reenableKeyguard(); //释放wakeLock,关灯 wl.release(); } }
Example 15
Source File: peService.java From styT with Apache License 2.0 | 5 votes |
@Override protected void onServiceConnected() { super.onServiceConnected(); // 获取电源管理器对象 PowerManager pm = (PowerManager) HApp.context.getSystemService(Context.POWER_SERVICE); // 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright"); KeyguardManager km = (KeyguardManager) HApp.context.getSystemService(Context.KEYGUARD_SERVICE); kl = km.newKeyguardLock("unLock"); //初始化屏幕的监听 ScreenListener screenListener = new ScreenListener(HApp.context); screenListener.begin(new ScreenListener.ScreenStateListener() { @Override public void onScreenOn() { // Log.e("ScreenListener", "屏幕打开了"); } @Override public void onScreenOff() { //在屏幕关闭的时候,进行锁屏,不执行的话,锁屏就失效了,因为要实现锁屏状态下也可以进行抢红包。 //Log.e("ScreenListener", "屏幕关闭了"); if (kl != null) { kl.disableKeyguard(); kl.reenableKeyguard(); } } @Override public void onUserPresent() { //Log.e("ScreenListener", "解锁了"); } }); }
Example 16
Source File: WatchServices.java From WearPay with GNU General Public License v2.0 | 5 votes |
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 17
Source File: KeyguardLock.java From AndroidBase with Apache License 2.0 | 4 votes |
public KeyguardLock(Context context, String tag) { //获取系统服务 keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); //初始化键盘锁,可以锁定或解开键盘锁 keyguardLock = keyguardManager.newKeyguardLock(tag); }
Example 18
Source File: KeyguardLockUtils.java From SprintNBA with Apache License 2.0 | 4 votes |
public KeyguardLockUtils(Context context, String tag) { //获取系统服务 keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); //初始化键盘锁,可以锁定或解开键盘锁 keyguardLock = keyguardManager.newKeyguardLock(tag); }
Example 19
Source File: ApplicationUtil.java From RxAndroidBootstrap with Apache License 2.0 | 4 votes |
/** * 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 20
Source File: KeyguardLock.java From android-common with Apache License 2.0 | 4 votes |
public KeyguardLock(Context context, String tag) { //获取系统服务 keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); //初始化键盘锁,可以锁定或解开键盘锁 keyguardLock = keyguardManager.newKeyguardLock(tag); }