Home > Software engineering >  Open Android credentials Setup programmatically
Open Android credentials Setup programmatically

Time:01-21

To display sensible data users can enable authentication in my app. I am using device security

You can get there from settings here:

security

What i am looking for is something like this: Here we navigate the user to some other android settings.

Intent intent2 = new Intent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  intent2.setAction(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
  intent2.putExtra(android.provider.Settings.EXTRA_APP_PACKAGE, getPackageName());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
  intent2.setAction(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
  intent2.putExtra("app_package", getPackageName());
  intent2.putExtra("app_uid", getApplicationInfo().uid);
} else {
  intent2.setAction(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
  intent2.addCategory(Intent.CATEGORY_DEFAULT);
  intent2.setData(Uri.parse("package:"   getPackageName()));
}
startActivity(intent2);

CodePudding user response:

Just figured it out.

There are 3 viable options to use: Settings.ACTION_BIOMETRIC_ENROLL, Settings.ACTION_FINGERPRINT_ENROLL and Settings.ACTION_SECURITY_SETTINGS.

Final implementation I use is:

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

Settings.ACTION_FINGERPRINT_ENROLL opens this: After chosing backup lock screen method and setup the chosen method, the device will ask you to register a fingerprint. ACTION_FINGERPRINT_ENROLL

Settings.ACTION_SECURITY_SETTINGS opens this: ACTION_SECURITY_SETTINGS

In lack of a device higher than Android Build "R" I could not test ACTION_BIOMETRIC_ENROLL, but I presume it will be similar to ACTION_FINGERPRINT_ENROLL.

If you want to see what options there are to open android settings. You can just use "CTRL" "mouse click" on any Settings.XXX (ACTION_SECURITY_SETTINGS, ACTION_FINGERPRINT_ENROLL, ...) in Android Studio. You will then see "..\android\platforms\android-31\android.jar!\android\provider\Settings.class" Settings options

In case you struggle to figure out which API version is described with "Build.VERSION_CODES.P" you can also click "CTRL" "Mose Click" on the Build version (P, O, ...). You will then see this: Build versions

  •  Tags:  
  • Related