2015-08-26 38 views

回答

1

我有代碼,是更通用的和平,所以,你只需要發送的包名作爲參數傳遞給方法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商店,並可能會下載它。

因此,只需撥打openApp(context, "com.google.android.apps.authenticator2");即可打開Goog​​le Authenticator應用。

編輯

您可以致電谷歌身份驗證與已經這樣設置的所有值:

String uri = "otpauth://totp/whatever:" + email + "?secret=" + yourKey + "&issuer=whatever" 
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); 
startActivity(intent); 
相關問題