0

I am using android's provided androidx settings library and I am having trouble adding biometrics to one of my settings. I am also using the androidx biometric library. The way android handles the results of biometrics is through call backs. This is problematic because the way I am trying to add biometric is by overriding fun onPreferenceTreeClick(preference: Preference?): Boolean. If I create a biometric prompt here, I am unable to stop the option from being clicked because right when my biometric prompt is instantiated, android will not wait for it to finish and instead handle it on its callback. How should I add biometrics to my settings? There is no overridable method that allows this (to my knowledge), and there is no way to do this with the biometric library.

1 Answers1

0

I ended up solving this by rejecting the new change initally and saving the value later on to be used if the user passed biometrics. If the user failed, nothing needed to happen because I rejected the change originally. But if the user passed the callback, I would make the change. Though this seems like the only logical option for a SwitchPreference, this wasn't apparent when doing a ListPreference.

In my specific implementation I added an onPreferenceChangeListener

findPreference<Preference>(BIOMETRIC_OPTION_KEY)?.setOnPreferenceChangeListener { preference, newValue ->
            if (newValue is String) {
                performBiometricFlow(preference.key, newValue)
            }

            false
        }

performBiometricFlow called the biometrics dialog library, and in the callback I ran a function that determined what was being clicked (based on the key), and ran the appropriate function. In this case a biometric option dialog was being clicked, and if it passed it would run this

private fun changeBiometricPreference(newValue: String) {
    findPreference<ListPreference>(BIOMETRIC_OPTION_KEY)?.value = newValue
}

This part saves the newValue that was originally supposed to be save by finding the ListPreference and reassigning it.