Ponsuyambu
Ponsuyambu

Reputation: 9006

Intent to launch fingerprint enrollment screen

How to launch finger print enrollment settings screen(Add fingerprint screen) from my app?

After enrolling finger print, is there any way to navigate back to my application? (with startActivityForResult)

Upvotes: 30

Views: 18258

Answers (6)

GareDeveloper
GareDeveloper

Reputation: 413

Suggested answer lack of an important point: if the user need to enroll a BIOMETRIC_STRONG type of biometry an Extra need to be added to the intent in order to correctly open BiometricEnrollActivity.

If I try to enroll a STRONG biometry with a WEAK biometry already enrolled the startActvity command fails to open the activity.

So the complete snippet used to bring the user to enroll a BIOMETRIC_STRONG is:

val intent: Intent = when {
  Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
     Intent(Settings.ACTION_BIOMETRIC_ENROLL).putExtra(EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, BiometricManager.Authenticators.BIOMETRIC_STRONG)
  }
   Build.VERSION.SDK_INT >= Build.VERSION_CODES.P -> {
     Intent(Settings.ACTION_FINGERPRINT_ENROLL)
   }
   else -> {
     Intent(Settings.ACTION_SECURITY_SETTINGS)
   }
}

if(intent.resolveActivity(context!!.packageManager) != null){
   startActivity(intent)
  }else{
   startActivity(Intent(Settings.ACTION_SETTINGS))
}

Upvotes: 13

Mostafa Hemmati
Mostafa Hemmati

Reputation: 11

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    startActivity(new Intent(Settings.ACTION_BIOMETRIC_ENROLL));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    startActivity(new Intent(Settings.ACTION_FINGERPRINT_ENROLL));
} else {
    startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
}

Upvotes: 1

Devendra
Devendra

Reputation: 3444

Solution: If your target API level is 30 and above

Settings.ACTION_FINGERPRINT_ENROLL was deprecated in API level 30 see

Use this:

startActivity(Intent(Settings.ACTION_BIOMETRIC_ENROLL))

But may this will not support in all android devices due to custom os,

I suggeset use like this:

try {
       startActivity(Intent(Settings.ACTION_BIOMETRIC_ENROLL))
} catch (e: Exception) {
       startActivity(Intent(Settings.ACTION_SETTINGS))
}

Upvotes: 2

Martin Zeitler
Martin Zeitler

Reputation: 76809

with API >= P there is Settings.ACTION_FINGERPRINT_ENROLL & BiometricPrompt.

@RequiresApi(api = Build.VERSION_CODES.P)
private void startFingerprintEnrollment(@NonNull AppCompatActivity activity) {
    Intent intent = new Intent(Settings.ACTION_FINGERPRINT_ENROLL);
    activity.startActivityForResult(intent, REQUESTCODE_FINGERPRINT_ENROLLMENT);
}

compared to API >= M:

@SuppressWarnings("deprecation")
@RequiresApi(api = Build.VERSION_CODES.M)
private void gotoSecuritySettings(@NonNull AppCompatActivity activity) {
    Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
    activity.startActivityForResult(intent, REQUESTCODE_SECURITY_SETTINGS);
}

think this is the FingerprintEnrollIntroduction ...

onboarding activity for fingerprint enrollment.

Upvotes: 21

Karol Kulbaka
Karol Kulbaka

Reputation: 1274

Suggested answer won't work for example on Huawei P9. Fingerprint settings on this model is available from: startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));.

Another thing is that when you launch system settings on your app task, enroll new fingerprint and return by back press you won't be able to encrypt any message on first authorization. The best thing is if user set app to background and enroll finger on his own, then restore app, encrypting will work. I have no idea what is the reason of such behaviour, so I suggest to just inform user about posibility of enroll finger.

Upvotes: 6

Ponsuyambu
Ponsuyambu

Reputation: 9006

After reading the docs, I found out that as of now, there is no such intent action available. I launched the security settings(where fingerprints option available) with the below Intent.

startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS));

Upvotes: 22

Related Questions