打算打开 Google 身份验证器 [英] Intent to Open Google Authenticator

查看:35
本文介绍了打算打开 Google 身份验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过 Intent 打开 Google Authenticator.如果可以,是否可以用已经填好的密钥打开,方便用户使用?

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?

推荐答案

我有更通用的代码和平,因此,您只需要将包名称作为参数发送到方法 openApp(上下文上下文,String packageName)

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);
}

这样,即使设备没有您尝试启动的应用,用户也会被您的应用驱动到 Play 商店并可能下载它.

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.

因此,只需调用 openApp(context, "com.google.android.apps.authenticator2"); 即可打开 Google 身份验证器应用.

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

编辑

您可以使用已设置的所有值调用 Google 身份验证器,如下所示:

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);

这篇关于打算打开 Google 身份验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆