Java Code Examples for android.hardware.fingerprint.FingerprintManager#hasEnrolledFingerprints()

The following examples show how to use android.hardware.fingerprint.FingerprintManager#hasEnrolledFingerprints() . 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: FingerprintActivity.java    From AndroidSamples with Apache License 2.0 6 votes vote down vote up
/**
 * 判断是否支持指纹(先用Android M的方式来判断)
 */
private boolean isSupportFingerprint() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        Toast.makeText(this, "您的系统版本过低,不支持指纹功能", Toast.LENGTH_SHORT).show();
        return false;
    } else {
        KeyguardManager keyguardManager = getSystemService(KeyguardManager.class);
        FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);

        if (!fingerprintManager.isHardwareDetected()) {
            Toast.makeText(this, "您的手机不支持指纹功能", Toast.LENGTH_SHORT).show();
            return false;
        } else if (!keyguardManager.isKeyguardSecure()) {
            Toast.makeText(this, "您还未设置锁屏,请先设置锁屏并添加一个指纹", Toast.LENGTH_SHORT).show();
            return false;
        } else if (!fingerprintManager.hasEnrolledFingerprints()) {
            Toast.makeText(this, "您至少需要在系统设置中添加一个指纹", Toast.LENGTH_SHORT).show();
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: FragmentPassCodeViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void checkFingerPrint() {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        if (ActivityCompat.checkSelfPermission(G.fragmentActivity, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        if (fingerprintManager != null) {
            if (!fingerprintManager.isHardwareDetected()) {
                deviceHasFingerPrint = false;
            } else if (!fingerprintManager.hasEnrolledFingerprints()) {
                deviceHasFingerPrint = false;
            } else {
                deviceHasFingerPrint = true;
            }
        }
    }
}
 
Example 3
Source File: AndroidSecurityBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
    public boolean supportsFingerprint(StrongReference<NSError> error) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            KeyguardManager keyguardManager
                    = (KeyguardManager) MainActivity.current().getSystemService(KEYGUARD_SERVICE);
            fingerprintManager
                    = (FingerprintManager) MainActivity.current().getSystemService(FINGERPRINT_SERVICE);

            if (!fingerprintManager.isHardwareDetected()) {
                error.set(new NSError(LAErrorDomain, LAError.TouchIDNotAvailable, getUserInfo("Device has no fingerprint sensor")));
                return false;
            }

            if (!fingerprintManager.hasEnrolledFingerprints()) {
                error.set(new NSError(LAErrorDomain, LAError.TouchIDNotEnrolled, getUserInfo("No identities are enrolled")));
                return false;
            }

            if (!keyguardManager.isKeyguardSecure()) {
                error.set(new NSError(LAErrorDomain, LAError.PasscodeNotSet, getUserInfo("A passcode isn’t set on the device.")));
//                return false;
            }
            return true;
        }
        return false;
    }
 
Example 4
Source File: SignTransactionDialog.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private static FingerprintManager fingerprintUnlockSupported(Context ctx)
{
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return null;
    }
    if (ctx.checkSelfPermission(Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }

    FingerprintManager fpManager = (FingerprintManager) ctx.getSystemService(Context.FINGERPRINT_SERVICE);
    if (fpManager == null || !fpManager.isHardwareDetected() || !fpManager.hasEnrolledFingerprints()) {
        return null;
    }

    return fpManager;
}
 
Example 5
Source File: MainActivity.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public boolean supportFingerprint() {
    if (Build.VERSION.SDK_INT < 23) {
        Toast.makeText(this, "您的系统版本过低,不支持指纹功能", Toast.LENGTH_SHORT).show();
        return false;
    } else {
        KeyguardManager keyguardManager = getSystemService(KeyguardManager.class);
        FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);
        if (!fingerprintManager.isHardwareDetected()) {
            Toast.makeText(this, "您的手机不支持指纹功能", Toast.LENGTH_SHORT).show();
            return false;
        } else if (!keyguardManager.isKeyguardSecure()) {
            Toast.makeText(this, "您还未设置锁屏,请先设置锁屏并添加一个指纹", Toast.LENGTH_SHORT).show();
            return false;
        } else if (!fingerprintManager.hasEnrolledFingerprints()) {
            Toast.makeText(this, "您至少需要在系统设置中添加一个指纹", Toast.LENGTH_SHORT).show();
            return false;
        }
    }
    return true;
}
 
Example 6
Source File: AppLockUtils.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static boolean hasDeviceFingerprintSupport(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        return fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints();
    } else {
        return false;
    }
}
 
Example 7
Source File: Whorlwind.java    From whorlwind with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
static boolean hasEnrolledFingerprints(FingerprintManager fingerprintManager) {
  try {
    return fingerprintManager.hasEnrolledFingerprints();
  } catch (IllegalStateException e) {
    // see https://github.com/square/whorlwind/issues/36
    Log.w(TAG, "Cannot know if device has enrolled fingerprints", e);
    return false;
  }
}
 
Example 8
Source File: AppLockUtils.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 5 votes vote down vote up
public static boolean hasDeviceFingerprintSupport(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        return fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints();
    } else {
        return false;
    }
}
 
Example 9
Source File: Utils.java    From PasscodeView with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the device has any fingerprint registered?
 * <p>
 * If no fingerprint registered, use {@link #openSecuritySettings(Context)} to open security settings.
 *
 * @param context instance
 * @return true if any fingerprint is register.
 */
@SuppressWarnings({"MissingPermission", "WeakerAccess"})
public static boolean isFingerPrintEnrolled(Context context) {
    // Check if we're running on Android 6.0 (M) or higher
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

        //Fingerprint API only available on from Android 6.0 (M)
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        return fingerprintManager != null
                && fingerprintManager.isHardwareDetected()
                && fingerprintManager.hasEnrolledFingerprints();
    } else {
        return false;
    }
}
 
Example 10
Source File: MarshmallowReprintModule.java    From reprint with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasFingerprintRegistered() throws SecurityException {
    final FingerprintManager fingerprintManager = fingerprintManager();
    if (fingerprintManager == null) return false;
    // Some devices with fingerprint sensors throw an IllegalStateException when trying to parse an
    // internal settings file during this call. See #29.
    try {
        return fingerprintManager.hasEnrolledFingerprints();
    } catch (IllegalStateException e) {
        logger.logException(e, "MarshmallowReprintModule: hasEnrolledFingerprints failed unexpectedly");
        return false;
    }
}
 
Example 11
Source File: ExampleFidoUafActivity.java    From UAF with Apache License 2.0 5 votes vote down vote up
private boolean supportsFingerprintAuth() {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
       FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);

       // noinspection ResourceType
       return fingerprintManager.isHardwareDetected()
               && fingerprintManager.hasEnrolledFingerprints();
   }

   return false;
}
 
Example 12
Source File: Fingerprint.java    From Fingerprint with MIT License 5 votes vote down vote up
/**
 * Check if fingerprint authentication is supported by the device and if a fingerprint is enrolled in the device.
 * @param context an activity context
 * @return a boolean value
 */
public static boolean isAvailable(Context context){
    FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
    if(fingerprintManager!=null){
        return (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints());
    }
    return false;
}
 
Example 13
Source File: ConfirmationDialog.java    From SightRemote with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("NewApi")
public static boolean isFingerprintScannerAvailable() {
    if (ContextCompat.checkSelfPermission(SightRemote.getInstance(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED)
        return false;
    FingerprintManager fingerprintManager = getFingerprintManager();
    if (fingerprintManager == null) return false;
    if (!fingerprintManager.isHardwareDetected()) return false;
    if (!fingerprintManager.hasEnrolledFingerprints()) return false;
    return true;
}
 
Example 14
Source File: DeviceAvailability.java    From react-native-secure-storage with MIT License 5 votes vote down vote up
public static boolean isFingerprintAuthAvailable(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        FingerprintManager fingerprintManager =
                (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        return fingerprintManager.isHardwareDetected() &&
                fingerprintManager.hasEnrolledFingerprints();
    }
    return false;
}
 
Example 15
Source File: SetSecurityActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean hasEnrolledFingerprints(FingerprintManager fingerprintManager) {
    try {
        return fingerprintManager.isHardwareDetected()
            && fingerprintManager.hasEnrolledFingerprints();
    } catch (Throwable e) {
        return false;
    }
}
 
Example 16
Source File: FingerPrint.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean checkFinger(Context ctx) {

    // Keyguard Manager
    KeyguardManager keyguardManager = (KeyguardManager) ctx.getSystemService(KEYGUARD_SERVICE);
    // Fingerprint Manager
    FingerprintManager fingerprintManager = (FingerprintManager) ctx.getSystemService(FINGERPRINT_SERVICE);

    try {
        // Check if the fingerprint sensor is present
        if (!fingerprintManager.isHardwareDetected()) {
            // Update the UI with a message
            StringUtils.showToast(ctx, ctx.getString(R.string.fp_not_supported));
            return false;
        }

        if (!fingerprintManager.hasEnrolledFingerprints()) {
            StringUtils.showToast(ctx, ctx.getString(R.string.fp_not_configured));
            return false;
        }

        if (!keyguardManager.isKeyguardSecure()) {
            StringUtils.showToast(ctx, ctx.getString(R.string.fp_not_enabled_sls));
            return false;
        }
    } catch (SecurityException se) {
        se.printStackTrace();
    }
    return true;
}
 
Example 17
Source File: BiometricPromptCompat.java    From BiometricPromptCompat with Apache License 2.0 4 votes vote down vote up
public static boolean hasEnrolledFingerprints(@NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final FingerprintManager manager = context.getSystemService(FingerprintManager.class);
        return manager != null && manager.hasEnrolledFingerprints();
    } else {
        Log.e(TAG, "Device software version is too low so we return " +
                "hasEnrolledFingerprints=false instead. Recommend to check software version " +
                "by yourself before using BiometricPromptCompat.");
        return false;
    }
}
 
Example 18
Source File: FingerprintManagerCompatApi23.java    From FingerprintIdentify with MIT License 4 votes vote down vote up
public static boolean hasEnrolledFingerprints(Context context) {
    final FingerprintManager fp = getFingerprintManagerOrNull(context);
    return (fp != null) && fp.hasEnrolledFingerprints();
}
 
Example 19
Source File: NativeFingerprint.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasRegisteredFingerprint() throws SecurityException {
    final FingerprintManager fingerprintManager = getFingerprintManager();
    return fingerprintManager != null && fingerprintManager.hasEnrolledFingerprints();
}
 
Example 20
Source File: FingerprintDialog.java    From Fingerprint with MIT License 2 votes vote down vote up
/**
 * Check if a fingerprint scanner is available and if at least one finger is enrolled in the phone.
 * @param context A context
 * @return True is authentication is available, False otherwise
 */
public static boolean isAvailable(Context context){
    FingerprintManager manager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
    return (manager!=null && manager.isHardwareDetected() && manager.hasEnrolledFingerprints());
}