Android I / O Widget

What is the best way to set up a widget in Android to enter a four-digit PIN?

I currently have:

<EditTextPreference 
  android:title="PIN" 
  android:summary="Your PIN number"
  android:key="password"
  android:numeric="integer"
  android:maxLength="4"
  android:password="true"
/>

This works very well, but there is no way to limit the input to at least 4 digits. Is it so if someone set a PIN in the settings? Or is there a better way?

By the way, before people comment on the security implications, I did not select a 4-digit PIN code, it is designed to connect to a third-party system, and I cannot change it. And no, this is not for banking.

+3
source share
2 answers

You can add OnPreferenceChangeListener and check the password length there.

eg. if the preference function is used:

findPreference("password").setOnPreferenceChangeListener( new OnPreferenceChangeListener(){
    public boolean  onPreferenceChange  (Preference preference, Object newValue){
        if ((String)newValue).length == 4)
            super.onPreferenceChange(preference, newValue);
        else
            Toast.makeText(this, "The PIN must have 4 digits", Toast.LENGTH_LONG).show();
    }
});
+3

Github , 4 .

0

Source: https://habr.com/ru/post/1765960/


All Articles