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:
1
Cotter.initBiometricSwitch(context, fragmentActivity, activity, cotterBiometricCallback);
Copied!
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
1
CotterBiometricCallback cotterBiometricCallback = new CotterBiometricCallback() {
2
@Override
3
public void onSuccess(boolean enrolled) {
4
res.setText("Success" + enrolled);
5
updateMethods();
6
}
7
​
8
@Override
9
public void onCanceled() {
10
res.setText("Canceled");
11
updateMethods();
12
}
13
​
14
@Override
15
public void onError(String s) {
16
res.setText("Error" + s);
17
updateMethods();
18
}
19
};
Copied!
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
1
Cotter.initBiometricSwitch(Context ctx, FragmentActivity fragmentAct, Activity act, CotterBiometricCallback callback)
Copied!
Example:
MainActivity.java -> OnCreate
1
Cotter.initBiometricSwitch(this, this, this, cotterBiometricCallback);
Copied!

3. Enable Biometric

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

4. Disable Biometric

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

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:
1
Cotter.methods.biometricEnrolled(new CotterMethodChecker() {
2
@Override
3
public void onCheck(boolean isEnrolled) {
4
// Check if biometric enrolled
5
bioEnrolled.setText("Biometric enrolled: " + isEnrolled);
6
}
7
});
Copied!
​

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

1
Cotter.methods.biometricAvailable(CotterMethodChecker callback)
Copied!
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:
1
Cotter.methods.biometricAvailable(new CotterMethodChecker() {
2
@Override
3
public void onCheck(boolean b) {
4
// Check if biometric available and enabled
5
bioAvailable.setText("Biometric available: " + b);
6
}
7
});
Copied!

2. Check if Biometrics is enrolled in the current device

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

3. Check if Pin is enrolled

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

Change Pin

Starting the PinChange flow is exactly the same as starting the PinEnrollment flow.
1
Cotter.PinChange.startFlow(view, CallBack.class, "EVENT TAG");
Copied!
Example:
1
// Inside your app, use a button onClick that calls
2
// openPinChange to start the flow
3
public void openPinChange(View view) {
4
Cotter.PinChange.startFlow(view, Dashboard.class, "PIN_CHANGE");
5
}
Copied!
Last modified 1yr ago