本文整理匯總了Java中android.app.KeyguardManager.isKeyguardSecure方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyguardManager.isKeyguardSecure方法的具體用法?Java KeyguardManager.isKeyguardSecure怎麽用?Java KeyguardManager.isKeyguardSecure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.KeyguardManager
的用法示例。
在下文中一共展示了KeyguardManager.isKeyguardSecure方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
}
示例3: 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);
}
}
示例4: 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();
}
});
}
示例5: 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);
}
}
示例6: isFingerAvailable
import android.app.KeyguardManager; //導入方法依賴的package包/類
/**
* 判斷指紋是否可用, 1:有指紋模塊, 2:錄入了指紋
*/
public static boolean isFingerAvailable(Context context) {
if (Build.VERSION.SDK_INT < 23) {
return false;
}
FingerprintManager manager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
KeyguardManager mKeyManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
//權限檢查
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
//判斷硬件是否支持指紋識別
if (!manager.isHardwareDetected()) {
return false;
}
//判斷 是否開啟鎖屏密碼
if (!mKeyManager.isKeyguardSecure()) {
return false;
}
//判斷是否有指紋錄入
if (!manager.hasEnrolledFingerprints()) {
return false;
}
return true;
}
示例7: isStandardKeyguardState
import android.app.KeyguardManager; //導入方法依賴的package包/類
public boolean isStandardKeyguardState() {
boolean isStandardKeyguqrd = false;
KeyguardManager keyManager =(KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
if (null != keyManager) {
isStandardKeyguqrd = keyManager.isKeyguardSecure();
}
return isStandardKeyguqrd;
}
示例8: isLockScreenDisabled
import android.app.KeyguardManager; //導入方法依賴的package包/類
private boolean isLockScreenDisabled() {
KeyguardManager km = (KeyguardManager) this.reactContext.getSystemService(Context.KEYGUARD_SERVICE);
if (km.isKeyguardSecure())
return true;
else
return false;
}
示例9: authenticateUser
import android.app.KeyguardManager; //導入方法依賴的package包/類
@ReactMethod
public void authenticateUser(String userName, String passWord, Callback errorCallback,
Callback successCallback) {
activityContext = getCurrentActivity();
this.successCallback = successCallback;
this.errorCallback = errorCallback;
String errorMessage = null;
//Check if device is not Rooted
if (RootUtil.isDeviceRooted()) {
fingerprintManager = FingerprintManagerCompat.from(AppContext);
keyguardManager = (KeyguardManager) AppContext.getSystemService(Context.KEYGUARD_SERVICE);
//keyguardManager = AppContext.getSystemService(KeyguardManager.class);
// fingerprintManager = AppContext.getSystemService(FingerprintManager.class);
jsonObject = new JSONObject();
try {
jsonObject.put(AppConstants.USER_NAME, userName);
jsonObject.put(AppConstants.PASS_WORD, passWord);
} catch (JSONException e) {
e.printStackTrace();
}
// Check whether the device has a Fingerprint sensor.
if (!fingerprintManager.isHardwareDetected()) {
errorMessage = "Your Device does not have a Fingerprint Sensor";
errorCallback.invoke(errorMessage);
} else {
// Checks whether fingerprint permission is set on manifest
if (ActivityCompat.checkSelfPermission(AppContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
errorMessage = "Fingerprint authentication permission not enabled";
errorCallback.invoke(errorMessage);
} else {
// Check whether at least one fingerprint is registered
if (!fingerprintManager.hasEnrolledFingerprints()) {
errorMessage = "Go to 'Settings -> Security -> Fingerprint' and register at least one fingerprint";
errorCallback.invoke(errorMessage);
} else {
// Checks whether lock screen security is enabled or not
if (!keyguardManager.isKeyguardSecure()) {
errorMessage = "Secure lock screen hasn't set up.\n"
+ "Go to 'Settings -> Security -> Fingerprint' to set up a fingerprint";
errorCallback.invoke(errorMessage);
} else {
//Generate key
generateKey();
//initialize cipher and pass it to FingerPrint scanner
if (cipherInit()) {
//Create dialog
FingerprintAuthenticationDialogFragment fragment
= new FingerprintAuthenticationDialogFragment(BiometricModule.this);
//Assign crypto Object
fragment.setCryptoObject(new FingerprintManagerCompat.CryptoObject(defaultCipher));
//Start Authentication
fragment.show(activityContext.getFragmentManager(), DIALOG_FRAGMENT_TAG);
}
}
}
}
}
} else {
errorMessage = "Fingerprint authentication feature does not work on rooted devices";
errorCallback.invoke(errorMessage);
//clear stored credentials
flushFileSystem();
}
}
開發者ID:hiteshsahu,項目名稱:FingerPrint-Authentication-With-React-Native-Android,代碼行數:79,代碼來源:BiometricModule.java
示例10: onCreate
import android.app.KeyguardManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
mFingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
// Checking fingerprint permission.
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.USE_FINGERPRINT) !=
PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this,
"Fingerprint authentication permission not enabled",
Toast.LENGTH_LONG).show();
return;
}
// Checking Device support fingerprint or not.
if (mFingerprintManager.isHardwareDetected()) {
// Not setting lock screen with imprint.
if (!mKeyguardManager.isKeyguardSecure()) {
Toast.makeText(this,
"Lock screen security not enabled in Settings",
Toast.LENGTH_LONG).show();
return;
}
// Not registered at least one fingerprint in Settings.
if (!mFingerprintManager.hasEnrolledFingerprints()) {
Toast.makeText(this,
"Register at least one fingerprint in Settings",
Toast.LENGTH_LONG).show();
return;
}
generateKey();
if (initCipher()) {
mCryptoObject = new FingerprintManager.CryptoObject(cipher);
mFingerprintHelper = new FingerprintHelper(this);
}
}
}
示例11: onCreate
import android.app.KeyguardManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
setTitle("Fingerprint Authentication");
auth_status = (SwirlView) findViewById(R.id.fp_stat);
auth_status.setState(SwirlView.State.ON,true);
// If you’ve set your app’s minSdkVersion to anything lower than 23, then you’ll need to verify that the device is running Marshmallow
// or higher before executing any fingerprint-related code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//Get an instance of KeyguardManager and FingerprintManager//
keyguardManager =
(KeyguardManager) getSystemService(KEYGUARD_SERVICE);
fingerprintManager =
(FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
//Check whether the device has a fingerprint sensor//
if (!fingerprintManager.isHardwareDetected()) {
// If a fingerprint sensor isn’t available, then inform the user that they’ll be unable to use your app’s fingerprint functionality//
MDToast.makeText(this,"Your device doesn't support fingerprint authentication",MDToast.LENGTH_LONG,MDToast.TYPE_INFO).show();
}
//Check whether the user has granted your app the USE_FINGERPRINT permission//
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
// If your app doesn't have this permission, then display the following text//
MDToast.makeText(this,"Please enable the fingerprint permission",MDToast.LENGTH_LONG,MDToast.TYPE_INFO).show();
}
//Check that the user has registered at least one fingerprint//
if (!fingerprintManager.hasEnrolledFingerprints()) {
// If the user hasn’t configured any fingerprints, then display the following message//
MDToast.makeText(this,"No fingerprint configured. Please register at least one fingerprint in your device's Settings",MDToast.LENGTH_LONG,MDToast.TYPE_INFO).show();
}
//Check that the lockscreen is secured//
if (!keyguardManager.isKeyguardSecure()) {
// If the user hasn’t secured their lockscreen with a PIN password or pattern, then display the following text//
MDToast.makeText(this,"Please enable lockscreen security in your device's Settings",MDToast.LENGTH_LONG,MDToast.TYPE_INFO).show();
} else {
try {
generateKey();
} catch (FingerprintException e) {
e.printStackTrace();
}
if (initCipher()) {
//If the cipher is initialized successfully, then create a CryptoObject instance//
cryptoObject = new FingerprintManager.CryptoObject(cipher);
// Here, I’m referencing the FingerprintHandler class that we’ll create in the next section. This class will be responsible
// for starting the authentication process (via the startAuth method) and processing the authentication process events//
FingerprintHandler helper = new FingerprintHandler(this,this);
helper.startAuth(fingerprintManager, cryptoObject);
}
}
}
}
示例12: checkAndEnableFingerPrintService
import android.app.KeyguardManager; //導入方法依賴的package包/類
/**
* @return Returns result code, an integer which can be any one of the following,<br/><br/>
* <b>FINGERPRINT_SENSOR_NOT_FOUND - 100<br/><br/></b>
* <b>PERMISSION_NOT_GRANTED_TO_ACCESS_FINGERPRINT_SENSOR - 200<br/><br/></b>
* <b>NO_FINGER_PRINTS_ENROLLED_IN_THE_DEVICE - 300<br/><br/></b>
* <b>OS_DOES_NOT_SUPPORT_FINGERPRINT_API - 400<br/><br/></b>
* <b>FAILED_INITIALISING_FINGERPRINT_SERVICE - 500<br/><br/></b>
* <b>FINGERPRINT_INITIALISATION_SUCCESS- 600<br/><br/></b>
* <b>KEY_GUARD_DISABLED - 700<br/><br/></b>
*/
public int checkAndEnableFingerPrintService() {
KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(KEYGUARD_SERVICE);
fingerprintManager = (FingerprintManager) mContext.getSystemService(FINGERPRINT_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!fingerprintManager.isHardwareDetected()) {
// Check if fingerprint sensor is available
return ResponseCode.FINGER_PRINT_SENSOR_UNAVAILABLE;
} else {
// Check if permission is granted to access fingerprint sensor
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
return ResponseCode.ENABLE_FINGER_PRINT_SENSOR_ACCESS;
} else {
// Check if device is keyguard protected
if (!keyguardManager.isKeyguardSecure()) {
return ResponseCode.DEVICE_NOT_KEY_GUARD_SECURED;
} else {
// Check if any fingerprints are enrolled
if (!fingerprintManager.hasEnrolledFingerprints()) {
return ResponseCode.NO_FINGER_PRINTS_ARE_ENROLLED;
} else {
if (generateKey()) {
if (cipherInit()) {
cryptoObject = new FingerprintManager.CryptoObject(cipher);
return ResponseCode.FINGERPRINT_SERVICE_INITIALISATION_SUCCESS;
} else {
return ResponseCode.FINGERPRINT_SERVICE_INITIALISATION_FAILED;
}
} else {
return ResponseCode.FINGERPRINT_SERVICE_INITIALISATION_FAILED;
}
}
}
}
}
} else {
return ResponseCode.OS_NOT_SUPPORTED;
}
}
示例13: onCreate
import android.app.KeyguardManager; //導入方法依賴的package包/類
@Override
@TargetApi(23)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fingerprint);
activity = this;
// Initializing both Android Keyguard Manager and Fingerprint Manager
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
textView = (TextView) findViewById(R.id.errorText);
// Check whether the device has a Fingerprint sensor.
if(!fingerprintManager.isHardwareDetected()){
/**
* An error message will be displayed if the device does not contain the fingerprint hardware.
* However if you plan to implement a default authentication method,
* you can redirect the user to a default authentication activity from here.
* Example:
* Intent intent = new Intent(this, DefaultAuthenticationActivity.class);
* startActivity(intent);
*/
textView.setText("Your Device does not have a Fingerprint Sensor");
}else {
// Checks whether fingerprint permission is set on manifest
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
textView.setText("Fingerprint authentication permission not enabled");
}else{
// Check whether at least one fingerprint is registered
if (!fingerprintManager.hasEnrolledFingerprints()) {
textView.setText("Register at least one fingerprint in Settings");
}else{
// Checks whether lock screen security is enabled or not
if (!keyguardManager.isKeyguardSecure()) {
textView.setText("Lock screen security not enabled in Settings");
}else{
generateKey();
if (cipherInit()) {
FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
FingerprintHandler helper = new FingerprintHandler(this, shortcutInfo);
helper.startAuth(fingerprintManager, cryptoObject);
}
}
}
}
}
}
示例14: onCreate
import android.app.KeyguardManager; //導入方法依賴的package包/類
@Override
@TargetApi(23)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fingerprint);
activity = this;
// Initializing both Android Keyguard Manager and Fingerprint Manager
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
textView = (TextView) findViewById(R.id.errorText);
// Check whether the device has a Fingerprint sensor.
if(!fingerprintManager.isHardwareDetected()){
/**
* An error message will be displayed if the device does not contain the fingerprint hardware.
* However if you plan to implement a default authentication method,
* you can redirect the user to a default authentication activity from here.
* Example:
* Intent intent = new Intent(this, DefaultAuthenticationActivity.class);
* startActivity(intent);
*/
textView.setText("Your Device does not have a Fingerprint Sensor");
}else {
// Checks whether fingerprint permission is set on manifest
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
textView.setText("Fingerprint authentication permission not enabled");
}else{
// Check whether at least one fingerprint is registered
if (!fingerprintManager.hasEnrolledFingerprints()) {
textView.setText("Register at least one fingerprint in Settings");
}else{
// Checks whether lock screen security is enabled or not
if (!keyguardManager.isKeyguardSecure()) {
textView.setText("Lock screen security not enabled in Settings");
}else{
generateKey();
if (cipherInit()) {
FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
FingerprintHandlerSettings helper = new FingerprintHandlerSettings(this);
helper.startAuth(fingerprintManager, cryptoObject);
}
}
}
}
}
}
示例15: isPassOrPinSet
import android.app.KeyguardManager; //導入方法依賴的package包/類
private static boolean isPassOrPinSet(Context context) {
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
return keyguardManager.isKeyguardSecure();
}