Cotter
  • 🚀Getting Started
  • Features & Concepts
    • 💬Sign In with Email/Phone Number
    • 🔐Sign In with Device
      • How it works
    • 🧬Sign In with WebAuthn
  • 📌Quickstart Guides
    • All Guides & Tutorials
    • HTML – Sign in with Email/Phone
    • React – Sign in with Email/Phone
    • React – WebAuthn
    • ▲ Next.js
    • Angular
    • Webflow
    • Bubble.io
    • Python SDK for a CLI
    • React Native – Sign in with Device
    • iOS – Sign in with Device
    • Flutter – Sign in with Device
  • 📘SDK Reference
    • Web
      • Sign In with Email/Phone Number
        • Customize the Form
        • Checking the email or phone before sending a verification code
        • Sending Code or Link via WhatsApp
        • Styling
        • Older SDK
          • Customize the Form
      • Sign in with Social Login
        • Getting Access Tokens from Social Login Providers
        • Github Instructions
        • Google Instructions
      • Sign In with WebAuthn
        • Register WebAuthn for a logged-in user
      • Sign In with Device
        • Steps for Pop Up Authentication Prompt
        • Advanced Customization for Login Form
        • Advanced Customization for Pop Up Authentication Prompt
      • Getting Access Token and Logged-In User Info
      • Sending Successful Form Submission
      • FAQ & Troubleshooting
    • React Native
      • Installation
      • Sign In with Device
        • Add Email/Phone Verification
        • Authenticate from a Non-Trusted Device
        • Add a new Trusted Device
        • Remove Trusted Device
      • Sign In with Email/Phone Number
      • Getting Stored OAuth Tokens and User Information
      • FAQ
      • Older SDK Versions
        • Sign in with Email/Phone
        • Sending Code via WhatsApp
        • Sign In with Device
          • Authenticate from a Non-Trusted Device
          • Add a new Trusted Device
          • Customization
    • Flutter
      • Sign In with Device
        • Add Email/Phone Verification
        • Authenticate from a Non-Trusted Device
      • Sign in with Email/Phone Number
      • Getting the Logged-in User
      • Getting OAuth Tokens
      • Signing a User Out
    • iOS
      • Sign In with Email/Phone Number
      • Sign In with Device
        • Authenticate from a Non-Trusted Device
        • Push Notification
        • Check if Trusted Device is Enrolled
        • Add a New Trusted Device
        • Remove Trusted Device
      • Older Versions
        • Biometric/Pin
    • Android
      • Sign In with Device
        • Authenticate from a Non-Trusted Device
        • Check if Trusted Device is Enrolled
        • Add a new Trusted Device
        • Remove Trusted Device
        • Customization
      • Sign In with Email/Phone Number
      • Biometric/Pin
        • Advanced Methods
        • Customization
        • Setting Strings
        • Styling
      • Older SDK Version
        • Sign In with Device
          • Authenticate from a Non-Trusted Device
    • Python (for CLI)
    • API for Other Mobile Apps or CLI
      • Verify Email/Phone Number
        • Handling URL Scheme
    • Backend: Handling Response
  • 🛡️ Protecting Your Account
    • Only Allow Your Website/App to Use Your API Key
    • Rate Limit
    • Enable reCAPTCHA to Protect Against Automated Abuse
  • 🗝️ Getting Access Token
    • Cotter's OAuth 2.0 Tokens Specification
    • Getting the Tokens
      • Get Tokens during Authentication
      • Using the Refresh Token
    • Storing and Removing Tokens
    • Renewing Expired Tokens
    • Verifying JWT Tokens
    • Requesting Custom Fields on your JWT Token
    • Older API
      • Using HTTP Requests
      • Getting the Tokens
        • During Authentication
          • During Email/Phone Verification
        • During enrolling Trusted Devices
  • 🔌API Reference
    • User API
      • User Object
    • OAuth Tokens API
      • Verify JWT Token using API (serverless)
      • Requesting Custom Claims on your Access Token
      • Older API
    • OAuth Tokens from Social Login
    • Event Object
    • Reset PIN API
  • Older API
    • Validating Cotter's Identity Token
    • Validating Cotter's Event Response
Powered by GitBook
On this page
  • 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
  1. SDK Reference
  2. Android
  3. Biometric/Pin

Advanced Methods

These are useful methods that you can use in your app to fully support Biometrics and PIN.

PreviousBiometric/PinNextCustomization

Last updated 4 years ago

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");
}
📘
Enable and disable Biometric
Check if Biometric or PIN are Enrolled
Change PIN