Example usage for android.hardware.fingerprint FingerprintManager isHardwareDetected

List of usage examples for android.hardware.fingerprint FingerprintManager isHardwareDetected

Introduction

In this page you can find the example usage for android.hardware.fingerprint FingerprintManager isHardwareDetected.

Prototype

@Deprecated
@RequiresPermission(USE_FINGERPRINT)
public boolean isHardwareDetected() 

Source Link

Document

Determine if fingerprint hardware is present and functional.

Usage

From source file:nl.hnogames.domoticz.Preference.Preference.java

private void setPreferences() {
    final android.preference.SwitchPreference MultiServerPreference = (android.preference.SwitchPreference) findPreference(
            "enableMultiServers");
    android.preference.Preference ServerSettings = findPreference("server_settings");
    android.preference.Preference PermissionsSettings = findPreference("permissionssettings");
    android.preference.Preference NotificationLogged = findPreference("notification_show_logs");
    android.preference.Preference fetchServerConfig = findPreference("server_force_fetch_config");
    android.preference.Preference resetApplication = findPreference("reset_settings");
    android.preference.ListPreference displayLanguage = (ListPreference) findPreference("displayLanguage");
    final android.preference.Preference registrationId = findPreference("notification_registration_id");
    android.preference.Preference GeoSettings = findPreference("geo_settings");
    android.preference.SwitchPreference WearPreference = (android.preference.SwitchPreference) findPreference(
            "enableWearItems");
    android.preference.Preference NFCPreference = findPreference("nfc_settings");
    android.preference.Preference QRCodePreference = findPreference("qrcode_settings");
    android.preference.Preference SpeechPreference = findPreference("speech_settings");
    android.preference.SwitchPreference EnableNFCPreference = (android.preference.SwitchPreference) findPreference(
            "enableNFC");
    android.preference.SwitchPreference EnableQRCodePreference = (android.preference.SwitchPreference) findPreference(
            "enableQRCode");
    android.preference.SwitchPreference EnableSpeechPreference = (android.preference.SwitchPreference) findPreference(
            "enableSpeech");
    android.preference.SwitchPreference EnableTalkBackPreference = (android.preference.SwitchPreference) findPreference(
            "talkBack");
    MultiSelectListPreference drawerItems = (MultiSelectListPreference) findPreference("enable_menu_items");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.SwitchPreference AlwaysOnPreference = (android.preference.SwitchPreference) findPreference(
            "alwayson");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.PreferenceScreen preferenceScreen = (android.preference.PreferenceScreen) findPreference(
            "settingsscreen");
    android.preference.PreferenceCategory premiumCategory = (android.preference.PreferenceCategory) findPreference(
            "premium_category");
    android.preference.Preference premiumPreference = findPreference("premium_settings");
    NotificationsMultiSelectListPreference notificationsMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "suppressNotifications");
    NotificationsMultiSelectListPreference alarmMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "alarmNotifications");
    android.preference.SwitchPreference ThemePreference = (android.preference.SwitchPreference) findPreference(
            "darkTheme");
    android.preference.Preference FingerPrintSettingsPreference = findPreference("SecuritySettings");
    android.preference.SwitchPreference FingerPrintPreference = (android.preference.SwitchPreference) findPreference(
            "enableSecurity");

    if (!BuildConfig.DEBUG) {
        PreferenceCategory oAndroidAutoCategory = (android.preference.PreferenceCategory) findPreference(
                "androidautocategory");
        PreferenceScreen oNotificationScreen = (android.preference.PreferenceScreen) findPreference(
                "notificationscreen");
        oNotificationScreen.removePreference(oAndroidAutoCategory);
    }//from   w  ww.  j  a va 2s  .co m

    List<String> notifications = mSharedPrefs.getReceivedNotifications();
    if (notifications == null || notifications.size() <= 0) {
        notificationsMultiSelectListPreference.setEnabled(false);
        alarmMultiSelectListPreference.setEnabled(false);
    } else {
        notificationsMultiSelectListPreference.setEnabled(true);
        alarmMultiSelectListPreference.setEnabled(true);
    }

    PermissionsSettings
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    permissionHelper.openSettingsScreen();
                    return true;
                }
            });

    drawerItems.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
            try {
                final HashSet selectedDrawerItems = (HashSet) newValue;
                if (selectedDrawerItems.size() < 1) {
                    showSnackbar(mContext.getString(R.string.error_atLeastOneItemInDrawer));
                    return false;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                return false;
            }
            return true;
        }
    });

    ThemePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_theme));
                        return false;
                    } else {
                        ((SettingsActivity) getActivity()).reloadSettings();
                        return true;
                    }
                }
            });

    MultiServerPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.multi_server));
                        return false;
                    }
                    return true;
                }
            });

    ServerSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (!MultiServerPreference.isChecked()) {
                Intent intent = new Intent(mContext, ServerSettingsActivity.class);
                startActivity(intent);
            } else {
                Intent intent = new Intent(mContext, ServerListSettingsActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    FingerPrintSettingsPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    mContext.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
                    return true;
                }
            });

    fetchServerConfig
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    UsefulBits.getServerConfigForActiveServer(mContext, true, new ConfigReceiver() {
                        @Override
                        public void onReceiveConfig(ConfigInfo settings) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_success));
                        }

                        @Override
                        public void onError(Exception error) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_failed));
                        }
                    }, null);
                    return true;
                }
            });

    displayLanguage
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    showRestartMessage();
                    return true;
                }
            });

    registrationId.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!PermissionsUtil.canAccessDeviceState(mContext)) {
                    permissionHelper.request(PermissionsUtil.INITIAL_DEVICE_PERMS);
                } else {
                    pushGCMRegistrationIds();
                }
            } else {
                pushGCMRegistrationIds();
            }
            return true;
        }
    });

    GeoSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.geofence));
                return false;
            } else {
                Intent intent = new Intent(mContext, GeoSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    EnableNFCPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_nfc));
                        return false;
                    }

                    if (NfcAdapter.getDefaultAdapter(mContext) == null) {
                        showSnackbar(mContext.getString(R.string.nfc_not_supported));
                        return false;
                    }
                    return true;
                }
            });

    EnableQRCodePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    }

                    return true;
                }
            });

    EnableSpeechPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    }
                    return true;
                }
            });

    EnableTalkBackPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_talk_back));
                        return false;
                    }
                    return true;
                }
            });

    NFCPreference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.category_nfc));
                return false;
            } else {
                Intent intent = new Intent(mContext, NFCSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    QRCodePreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, QRCodeSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    SpeechPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, SpeechSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    WearPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_wear));
                        return false;
                    }
                    return true;
                }
            });

    AlwaysOnPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.always_on_title));
                        return false;
                    }
                    return true;
                }
            });

    NotificationLogged
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    //show dialog
                    List<String> logs = mSharedPrefs.getLoggedNotifications();
                    if (logs != null && logs.size() > 0) {
                        Collections.reverse(logs);
                        new MaterialDialog.Builder(mContext)
                                .title(mContext.getString(R.string.notification_show_title))
                                .items((CharSequence[]) logs.toArray(new String[0])).show();
                    } else
                        UsefulBits.showSimpleToast(mContext, getString(R.string.notification_show_nothing),
                                Toast.LENGTH_LONG);
                    return true;
                }
            });

    //noinspection PointlessBooleanExpression
    if (!BuildConfig.LITE_VERSION) {
        preferenceScreen.removePreference(premiumCategory);
    } else {
        premiumPreference
                .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(android.preference.Preference preference) {
                        String packageID = mContext.getPackageName() + ".premium";
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id=" + packageID)));
                        } catch (android.content.ActivityNotFoundException ignored) {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("https://play.google.com/store/apps/details?id=" + packageID)));
                        }

                        return true;
                    }
                });
    }

    resetApplication
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        new MaterialDialog.Builder(mContext).title(R.string.category_Reset)
                                .content(R.string.are_you_sure).positiveText(R.string.ok)
                                .negativeText(R.string.cancel)
                                .onPositive(new MaterialDialog.SingleButtonCallback() {
                                    @SuppressLint("NewApi")
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {
                                        ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE))
                                                .clearApplicationUserData();
                                    }
                                }).show();
                    } else {
                        startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
                    }
                    return true;
                }
            });

    FingerPrintPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @SuppressLint("NewApi")
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object o) {
                    if (mSharedPrefs.isStartupSecurityEnabled())
                        return true;
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_startup_security));
                        return false;
                    } else {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                            UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_supported),
                                    Toast.LENGTH_LONG);
                            return false;
                        }
                        if (!PermissionsUtil.canAccessFingerprint(mContext)) {
                            permissionHelper.request(PermissionsUtil.INITIAL_FINGERPRINT_PERMS);
                        } else {
                            FingerprintManager fingerprintManager = (FingerprintManager) mContext
                                    .getSystemService(Context.FINGERPRINT_SERVICE);
                            if (ActivityCompat.checkSelfPermission(mContext,
                                    Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                                return false;
                            }
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                if (!fingerprintManager.isHardwareDetected()) {
                                    return false;
                                } else if (!fingerprintManager.hasEnrolledFingerprints()) {
                                    UsefulBits.showSimpleToast(mContext,
                                            getString(R.string.fingerprint_not_setup_in_android),
                                            Toast.LENGTH_LONG);
                                    return false;
                                } else {
                                    new MaterialDialog.Builder(mContext)
                                            .title(R.string.category_startup_security)
                                            .content(R.string.fingerprint_sure).positiveText(R.string.ok)
                                            .negativeText(R.string.cancel)
                                            .onPositive(new MaterialDialog.SingleButtonCallback() {
                                                @Override
                                                public void onClick(@NonNull MaterialDialog dialog,
                                                        @NonNull DialogAction which) {
                                                    mSharedPrefs.setStartupSecurityEnabled(true);
                                                    ((SettingsActivity) getActivity()).reloadSettings();
                                                }
                                            }).show();

                                    return false;
                                }
                            }
                        }
                    }
                    return false;
                }
            });
}