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

The following examples show how to use android.hardware.fingerprint.FingerprintManager#isHardwareDetected() . 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: 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 2
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 3
Source File: FingerPrintAuthHelper.java    From PasscodeView with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the finger print hardware is available.
 *
 * @param context instance of the caller.
 * @return true if finger print authentication is supported.
 */
@SuppressWarnings("MissingPermission")
private boolean checkFingerPrintAvailability(@NonNull 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);

        if (!fingerprintManager.isHardwareDetected()) {
            return false;
        } else return fingerprintManager.hasEnrolledFingerprints();
    } else {
        return false;
    }
}
 
Example 4
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 5
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 6
Source File: AppLockActivity.java    From LolliPin with MIT License 5 votes vote down vote up
/**
 * Init {@link FingerprintManager} of the {@link android.os.Build.VERSION#SDK_INT} is > to Marshmallow
 * and {@link FingerprintManager#isHardwareDetected()}.
 */
private void initLayoutForFingerprint() {
    mFingerprintImageView = (ImageView) this.findViewById(R.id.pin_code_fingerprint_imageview);
    mFingerprintTextView = (TextView) this.findViewById(R.id.pin_code_fingerprint_textview);
    if (mType == AppLock.UNLOCK_PIN && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mFingerprintManager = (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE);
        mFingerprintUiHelper = new FingerprintUiHelper.FingerprintUiHelperBuilder(mFingerprintManager).build(mFingerprintImageView, mFingerprintTextView, this);
        try {
        if (mFingerprintManager.isHardwareDetected() && mFingerprintUiHelper.isFingerprintAuthAvailable()
                && mLockManager.getAppLock().isFingerprintAuthEnabled()) {
                mFingerprintImageView.setVisibility(View.VISIBLE);
                mFingerprintTextView.setVisibility(View.VISIBLE);
                mFingerprintUiHelper.startListening();
            } else {
                mFingerprintImageView.setVisibility(View.GONE);
                mFingerprintTextView.setVisibility(View.GONE);
            }
        } catch (SecurityException e) {
            Log.e(TAG, e.toString());
            mFingerprintImageView.setVisibility(View.GONE);
            mFingerprintTextView.setVisibility(View.GONE);
        }
    } else {
        mFingerprintImageView.setVisibility(View.GONE);
        mFingerprintTextView.setVisibility(View.GONE);
    }
}
 
Example 7
Source File: PinLockTest.java    From LolliPin with MIT License 5 votes vote down vote up
public void testPinEnablingChecking() throws SecurityException {
    enablePin();

    //Go to unlock
    clickOnView(R.id.button_unlock_pin);
    solo.waitForActivity(CustomPinActivity.class);
    solo.assertCurrentActivity("CustomPinActivity", CustomPinActivity.class);

    //Test fingerprint if available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        ImageView fingerprintImageView = (ImageView) solo.getView(com.github.omadahealth.lollipin.lib.R.id.pin_code_fingerprint_imageview);
        TextView fingerprintTextView = (TextView) solo.getView(com.github.omadahealth.lollipin.lib.R.id.pin_code_fingerprint_textview);
        FingerprintManager fingerprintManager = (FingerprintManager) getActivity().getSystemService(Context.FINGERPRINT_SERVICE);
        FingerprintUiHelper fingerprintUiHelper = new FingerprintUiHelper.FingerprintUiHelperBuilder(fingerprintManager).build(fingerprintImageView, fingerprintTextView, (CustomPinActivity) solo.getCurrentActivity());
        if (fingerprintManager.isHardwareDetected() && fingerprintUiHelper.isFingerprintAuthAvailable()) {
            assertEquals(View.VISIBLE, solo.getView(R.id.pin_code_fingerprint_imageview).getVisibility());
            assertEquals(View.VISIBLE, solo.getView(R.id.pin_code_fingerprint_textview).getVisibility());
        } else {
            assertEquals(View.GONE, solo.getView(R.id.pin_code_fingerprint_imageview).getVisibility());
            assertEquals(View.GONE, solo.getView(R.id.pin_code_fingerprint_textview).getVisibility());
        }
    } else {
        assertEquals(View.GONE, solo.getView(R.id.pin_code_fingerprint_imageview).getVisibility());
        assertEquals(View.GONE, solo.getView(R.id.pin_code_fingerprint_textview).getVisibility());
    }

    //Enter the code
    clickOnView(R.id.pin_code_button_1);
    clickOnView(R.id.pin_code_button_2);
    clickOnView(R.id.pin_code_button_3);
    clickOnView(R.id.pin_code_button_4);

    //Check view
    solo.waitForActivity(MainActivity.class);
    solo.assertCurrentActivity("MainActivity", MainActivity.class);
}
 
Example 8
Source File: SystemPropertyProvider.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
public static boolean supportsFingerprint(Context ctx) {
    try {
        FingerprintManager fpm = (FingerprintManager) ctx.getSystemService(Context.FINGERPRINT_SERVICE);
        return (fpm != null && fpm.isHardwareDetected());
    } catch (Throwable t) {
        log("Error checkin for fingerprint support: " + t.getMessage());
        return false;
    }
}
 
Example 9
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 10
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 11
Source File: Utils.java    From PasscodeView with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the device have supported hardware fir the finger print scanner.
 *
 * @param context instance of the caller.
 * @return true if device have the hardware.
 */
@SuppressWarnings("MissingPermission")
@RequiresApi(api = Build.VERSION_CODES.M)
@RequiresPermission(allOf = {Manifest.permission.USE_FINGERPRINT})
public static boolean hasSupportedFingerprintHardware(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
    FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
    return fingerprintManager != null && fingerprintManager.isHardwareDetected();
}
 
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: BiometricPromptCompat.java    From BiometricPromptCompat with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public static boolean isHardwareDetected(@NonNull Context context) {
    if (isApiPSupported()) {
        final PackageManager pm = context.getPackageManager();
        return Arrays.stream(SUPPORTED_BIOMETRIC_FEATURES).anyMatch(pm::hasSystemFeature);
    } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final FingerprintManager fm = context.getSystemService(FingerprintManager.class);
        return fm != null && fm.isHardwareDetected();
    } else {
        Log.e(TAG, "Device software version is too low so we return " +
                "isHardwareDetected=false instead. Recommend to check software version " +
                "by yourself before using BiometricPromptCompat.");
        return false;
    }
}
 
Example 16
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 17
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 18
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 19
Source File: FingerprintUtil.java    From masterpassword with GNU General Public License v3.0 4 votes vote down vote up
public static boolean canUseFingerprint(boolean doSnackbar) {
    BaseActivity activity = App.get().getCurrentForegroundActivity();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        //Get an instance of KeyguardManager and FingerprintManager//
        KeyguardManager keyguardManager =
                (KeyguardManager) App.get().getSystemService(KEYGUARD_SERVICE);
        FingerprintManager fingerprintManager = (FingerprintManager) App.get().getSystemService(Context.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//
            if (doSnackbar)
                SnackbarUtil.showShort(activity, R.string.fingerprint_device_unsupported);
            return false;
        }
        //Check whether the user has granted your app the USE_FINGERPRINT permission//
        if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            // If your app doesn't have this permission, then display the following text//
            if (doSnackbar)
                SnackbarUtil.showShort(activity, R.string.fingerprint_permission);
            return false;
        }

        //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//
            if (doSnackbar)
                SnackbarUtil.showShort(activity, R.string.fingerprint_unconfigured);
            return false;
        }

        //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//
            if (doSnackbar)
                SnackbarUtil.showShort(activity, R.string.fingerprint_noLock);
            return false;
        }

        return true;
    } else {
        if (doSnackbar)
            SnackbarUtil.showShort(activity, R.string.fingerprint_device_unsupported);
        return false;
    }
}
 
Example 20
Source File: FingerprintManagerCompatApi23.java    From FingerprintIdentify with MIT License 4 votes vote down vote up
public static boolean isHardwareDetected(Context context) {
    final FingerprintManager fp = getFingerprintManagerOrNull(context);
    return (fp != null) && fp.isHardwareDetected();
}