本文整理汇总了Java中android.app.KeyguardManager类的典型用法代码示例。如果您正苦于以下问题:Java KeyguardManager类的具体用法?Java KeyguardManager怎么用?Java KeyguardManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyguardManager类属于android.app包,在下文中一共展示了KeyguardManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStart
import android.app.KeyguardManager; //导入依赖的package包/类
@SuppressLint("MissingPermission")
@Override
public void onStart() {
Application application = (Application) getTargetContext().getApplicationContext();
String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
// Unlock the device so that the tests can input keystrokes.
((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
.newKeyguardLock(simpleName)
.disableKeyguard();
// Wake up the screen.
PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
ON_AFTER_RELEASE, simpleName);
mWakeLock.acquire();
super.onStart();
}
示例2: requireAuthentication
import android.app.KeyguardManager; //导入依赖的package包/类
/**
* Require the user to authenticate using the configured LockScreen before accessing the credentials.
* This feature is disabled by default and will only work if the device is running on Android version 21 or up and if the user
* has configured a secure LockScreen (PIN, Pattern, Password or Fingerprint).
* <p>
* The activity passed as first argument here must override the {@link Activity#onActivityResult(int, int, Intent)} method and
* call {@link SecureCredentialsManager#checkAuthenticationResult(int, int)} with the received parameters.
*
* @param activity a valid activity context. Will be used in the authentication request to launch a LockScreen intent.
* @param requestCode the request code to use in the authentication request. Must be a value between 1 and 255.
* @param title the text to use as title in the authentication screen. Passing null will result in using the OS's default value.
* @param description the text to use as description in the authentication screen. On some Android versions it might not be shown. Passing null will result in using the OS's default value.
* @return whether this device supports requiring authentication or not. This result can be ignored safely.
*/
public boolean requireAuthentication(@NonNull Activity activity, @IntRange(from = 1, to = 255) int requestCode, @Nullable String title, @Nullable String description) {
if (requestCode < 1 || requestCode > 255) {
throw new IllegalArgumentException("Request code must a value between 1 and 255.");
}
KeyguardManager kManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
this.authIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? kManager.createConfirmDeviceCredentialIntent(title, description) : null;
this.authenticateBeforeDecrypt = ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && kManager.isDeviceSecure())
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && kManager.isKeyguardSecure()))
&& authIntent != null;
if (authenticateBeforeDecrypt) {
this.activity = activity;
this.authenticationRequestCode = requestCode;
}
return authenticateBeforeDecrypt;
}
示例3: setup
import android.app.KeyguardManager; //导入依赖的package包/类
@Before
public void setup() throws Throwable {
// espresso need the screen on
final Activity activity = mRule.getActivity();
mRule.runOnUiThread(new Runnable() {
@Override
public void run() {
KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock lock = km.newKeyguardLock(Context.KEYGUARD_SERVICE);
lock.disableKeyguard();
//turn the screen on
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
}
});
}
示例4: wakeAndUnlock
import android.app.KeyguardManager; //导入依赖的package包/类
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();
}
示例5: wakeAndUnlock
import android.app.KeyguardManager; //导入依赖的package包/类
private void wakeAndUnlock(boolean b)
{
if (b)
{
//获取电源管理器对象
mPowerManager = (PowerManager)getApplicationContext().getSystemService(Context.POWER_SERVICE);
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
mWakeLock = mPowerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//点亮屏幕
mWakeLock.acquire();
//得到键盘锁管理器对象
mKeyguardManager = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock = mKeyguardManager.newKeyguardLock("unLock");
//解锁
mKeyguardLock.disableKeyguard();
}
else
{
//锁屏
mKeyguardLock.reenableKeyguard();
//释放wakeLock,关灯
mWakeLock.release();
}}
示例6: wakeAndUnlock
import android.app.KeyguardManager; //导入依赖的package包/类
private void wakeAndUnlock(boolean b) {
Log.i(TAG, "解锁亮屏?:" + b);
if (b) {
//获取电源管理器对象
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
//点亮屏幕
wl.acquire();
//得到键盘锁管理器对象
km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
kl = km.newKeyguardLock("unLock");
//解锁
kl.disableKeyguard();
isWaked = true;
} else {
//锁屏
kl.reenableKeyguard();
//释放wakeLock,关灯
wl.release();
}
}
示例7: checkSensorState
import android.app.KeyguardManager; //导入依赖的package包/类
public static SensorState checkSensorState(Context context) {
if (checkFingerprintCompatibility(context)) {
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if (!keyguardManager.isKeyguardSecure()) {
return SensorState.NOT_BLOCKED;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !((FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE)).hasEnrolledFingerprints()) {
return SensorState.NO_FINGERPRINTS;
}
return SensorState.READY;
} else {
return SensorState.NOT_SUPPORTED;
}
}
示例8: handleIntent
import android.app.KeyguardManager; //导入依赖的package包/类
private void handleIntent(Intent intent) {
KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
if (currentMessageObject == null) {
currentMessageNum = 0;
}
getNewMessage();
}
示例9: initFingerPrint
import android.app.KeyguardManager; //导入依赖的package包/类
private void initFingerPrint(Context context) {
KeyguardManager keyguardManager =
(KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
FingerprintManager fingerprintManager =
(FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
if (!fingerprintManager.isHardwareDetected()) {
Toast.makeText(context, "Your device doesn't support fingerprint authentication", Toast.LENGTH_LONG).show();
} else if (context.checkSelfPermission(Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, "Please enable the fingerprint permission", Toast.LENGTH_LONG).show();
} else if (!fingerprintManager.hasEnrolledFingerprints()) {
Toast.makeText(
context,
"No fingerprint configured. Please register at least one fingerprint in your device's Settings",
Toast.LENGTH_LONG).show();
} else if (!keyguardManager.isKeyguardSecure()) {
Toast.makeText(
context,
"Please enable lock screen security in your device's Settings",
Toast.LENGTH_LONG).show();
} else {
fHandler = new FingerprintHandler(context);
}
}
示例10: onStart
import android.app.KeyguardManager; //导入依赖的package包/类
@SuppressWarnings("MissingPermission")
@Override
public void onStart() {
Application application = (Application) getTargetContext().getApplicationContext();
String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
// Unlock the device so that the tests can input keystrokes.
((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
.newKeyguardLock(simpleName)
.disableKeyguard();
// Wake up the screen.
PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
ON_AFTER_RELEASE, simpleName);
mWakeLock.acquire();
super.onStart();
}
示例11: wakeAndUnlock
import android.app.KeyguardManager; //导入依赖的package包/类
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();
}
}
示例12: onCreate
import android.app.KeyguardManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
Button purchaseButton = (Button) findViewById(R.id.purchase_button);
if (!mKeyguardManager.isKeyguardSecure()) {
// Show a message that the user hasn't set up a lock screen.
Toast.makeText(this,
"Secure lock screen hasn't set up.\n"
+ "Go to 'Settings -> Security -> Screenlock' to set up a lock screen",
Toast.LENGTH_LONG).show();
purchaseButton.setEnabled(false);
return;
}
createKey();
findViewById(R.id.purchase_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Test to encrypt something. It might fail if the timeout expired (30s).
tryEncrypt();
}
});
}
示例13: wakeAndUnlock
import android.app.KeyguardManager; //导入依赖的package包/类
public static void wakeAndUnlock() {
//获取电源管理器对象
PowerManager pm = getPowerManager();
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//点亮屏幕
wl.acquire(1000);
//得到键盘锁管理器对象
KeyguardManager km = getKeyguardManager();
KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
//解锁
kl.disableKeyguard();
}
示例14: wakeAndUnlock
import android.app.KeyguardManager; //导入依赖的package包/类
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();
}
示例15: showAuthScreen
import android.app.KeyguardManager; //导入依赖的package包/类
void showAuthScreen() {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(
Context.KEYGUARD_SERVICE);
if (!keyguardManager.isKeyguardSecure()) {
basicConfigFragment.unlockAppIDandSecret();
return;
}
Intent intent = keyguardManager
.createConfirmDeviceCredentialIntent(getString(R.string.unlock_auth_title),
getString(R.string.unlock_auth_explain));
if (intent != null) {
startActivityForResult(intent, 1);
}
}