3

Is there a way to, via Intent, open Google Authenticator. If yes, is it possible to open it with the key already filled, to make it practical for the user?

Gustafah88
  • 31
  • 1
  • 4

1 Answers1

4

I've a peace of code that is more generic, so, you just need to send the package name as a parameter to the method openApp(Context context, String packageName)

public static void openApp(Context context, String packageName) {

    PackageManager manager = context.getPackageManager();
    Intent i = manager.getLaunchIntentForPackage(packageName);
    if (i == null) {
        try {
            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
        } catch (android.content.ActivityNotFoundException anfe) {
            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
        }
        return;
    }
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    context.startActivity(i);
}

In this way, even if the device doesn't have the app that you are trying to launch, the user will be driven by your app to the Play Store and maybe download it.

So, just call openApp(context, "com.google.android.apps.authenticator2"); to open Google Authenticator app.

EDIT

You can call Google Authenticator with all the values already set like this:

String uri = "otpauth://totp/whatever:" + email + "?secret=" + yourKey + "&issuer=whatever"
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
Renan Nery
  • 3,475
  • 3
  • 19
  • 23