Advanced Methods
These are useful methods that you can use in your app to fully support Biometrics and PIN.
To complete the functionalities, we provide the following methods:

Enable and Disable Biometric

Biometrics entries are unique per device. When the user disable their biometrics, their biometrics enrollment for that device will be deleted from the database. When they enable biometrics, they are essentially enrolling that device again for biometrics, and therefore they will be prompted to verify the biometrics again.
To do enable/disable biometrics, you have to initialize Cotter's biometrics prompt first using:
Cotter.initBiometricSwitch(context, fragmentActivity, activity, cotterBiometricCallback);
Generally, context, fragmentActivity, and activity can be filled with this inside your activity.
Here is a step-by-step guide on enabling and disabling Biometrics

1. Create a Callback

This callback will called when biometric is enabled or disabled.
cotterBiometricCallback
CotterBiometricCallback cotterBiometricCallback = new CotterBiometricCallback() {
@Override
public void onSuccess(boolean enrolled) {
res.setText("Success" + enrolled);
updateMethods();
}
​
@Override
public void onCanceled() {
res.setText("Canceled");
updateMethods();
}
​
@Override
public void onError(String s) {
res.setText("Error" + s);
updateMethods();
}
};
onSuccess
onSuccess will be called when the biometric is successfully enabled or disabled.
  • If the user successfully disabled biometrics, we will call onSuccess(false). So enrolled = false here, because biometrics is no longer enrolled.
  • If the user successfully enabled biometrics, we will call onSuccess(true).
onCanceled
onCanceled will be called when the user try to enable biometrics, but they canceled the biometric prompt (dismissed the prompt).
onError
onError will be caleld when an error occur while enabling or disabling biometrics.

2. Initialize Cotter Biometric

You have to initialize Cotter Biometric before using it to enable or disable
Cotter.initBiometricSwitch(Context ctx, FragmentActivity fragmentAct, Activity act, CotterBiometricCallback callback)
Example:
MainActivity.java -> OnCreate
Cotter.initBiometricSwitch(this, this, this, cotterBiometricCallback);

3. Enable Biometric

Remember, you have to initialize Cotter Biometric first before calling this function.
Cotter.biometricPrompt.enableBiometric();

4. Disable Biometric

Remember, you have to initialize Cotter Biometric first before calling this function.
Cotter.biometricPrompt.disableBiometric();

5. Checking the Enrolled status of Biometric after enable/disable

You can check again if the biometric is correctly enabled/disabled using the function below:
Cotter.methods.biometricEnrolled(new CotterMethodChecker() {
@Override
public void onCheck(boolean isEnrolled) {
// Check if biometric enrolled
bioEnrolled.setText("Biometric enrolled: " + isEnrolled);
}
});
​

Check if Methods are Enrolled

You can check if an authentication method is enrolled and available for a user.

1. Check if Biometric is available

Cotter.methods.biometricAvailable(CotterMethodChecker callback)
This method is used to check if biometric is available on the user's device. You need to provide a callback of type CotterMethodChecker to handle the result.
Example:
Cotter.methods.biometricAvailable(new CotterMethodChecker() {
@Override
public void onCheck(boolean b) {
// Check if biometric available and enabled
bioAvailable.setText("Biometric available: " + b);
}
});

2. Check if Biometrics is enrolled in the current device

Cotter.methods.biometricEnrolled(CotterMethodChecker callback)
This method is used to check if biometric is enrolled. You need to provide a callback of type CotterMethodChecker to handle the result.
Example:
Cotter.methods.biometricEnrolled(new CotterMethodChecker() {
@Override
public void onCheck(boolean isEnrolled) {
// Check if biometric enrolled
bioEnrolled.setText("Biometric enrolled: " + isEnrolled);
}
});

3. Check if Pin is enrolled

Cotter.methods.pinEnrolled(CotterMethodChecker callback)
This method is used to check if pin is enrolled. You need to provide a callback of type CotterMethodChecker to handle the result.
Example:
Cotter.methods.pinEnrolled(new CotterMethodChecker() {
@Override
public void onCheck(boolean b) {
// Check if biometric available and enabled
pinEnrolled.setText("Pin Enrolled: " + b);
}
});
​

Change Pin

Starting the PinChange flow is exactly the same as starting the PinEnrollment flow.
Cotter.PinChange.startFlow(view, CallBack.class, "EVENT TAG");
Example:
// Inside your app, use a button onClick that calls
// openPinChange to start the flow
public void openPinChange(View view) {
Cotter.PinChange.startFlow(view, Dashboard.class, "PIN_CHANGE");
}
Copy link
Outline
Enable and Disable Biometric
1. Create a Callback
2. Initialize Cotter Biometric
3. Enable Biometric
4. Disable Biometric
5. Checking the Enrolled status of Biometric after enable/disable
Check if Methods are Enrolled
1. Check if Biometric is available
2. Check if Biometrics is enrolled in the current device
3. Check if Pin is enrolled
Change Pin