Launch Google Pay on "Add Payment Method" Screen

时间:2019-05-31 11:50:27

标签: c# android xamarin google-pay

we will be implementing In App Provisioning in our apps at a later date. For now, I'd like to be able to add a button which will launch the Google Pay app to allow a user to add a payment method.

I've seen code how to launch Google Play. I am hoping it is similar but with a different URI.

Could anyone help out please.

2 个答案:

答案 0 :(得分:0)

好的-还不完全到那里,但确实让我感到震惊,我只需要启动一个应用程序即可。 因此,为此,我将手机连接到PC并运行了Android设备监视器。 在我的手机上启动Google Pay,对小麦和谷壳进行分类,以找到当前为“ com.google.android.apps.walletnfcrel”的包裹名称。

再进行一次谷歌搜索,我找到了一种测试应用程序是否已安装的方法……

private bool isAppInstalled(String packageName)
{
    var context = Android.App.Application.Context;

    var pm = context.PackageManager;
    bool installed = false;
    try
    {
        pm.GetPackageInfo(packageName, Android.Content.PM.PackageInfoFlags.Activities);
        installed = true;

    }
    catch (Exception e)
    {
        //Handle this nicer
        installed = false;
    }
    return installed;
}

...然后安装它,我可以按以下方式启动它.....

        var googlePayPackageNAme = "com.google.android.apps.walletnfcrel";
        var context = Android.App.Application.Context;
        Intent gpIntent = context.PackageManager.GetLaunchIntentForPackage(googlePayPackageNAme);
        context.StartActivity(gpIntent);

暂时我对此感到满意.....要做的其他事情,但我稍后会尝试实际触发添加付款方式的过程。

感谢SO上的其他帖子。 希望这对其他人有帮助。

答案 1 :(得分:0)

我在我们的应用程序中想到了这个解决方案。该应用程序是使用React Native构建的,我实现了一个按钮,该按钮调用了本机Java模块中的方法(如果您想知道为什么我在这里使用Promise):

NativeModule.java

@ReactMethod
public void jumpToWallet(Promise promise) {
    // Check first if wallet is installed
    String packageName = "com.google.android.apps.walletnfcrel";
    Context appContext = reactContext.getApplicationContext();
    PackageManager pm = appContext.getPackageManager();
    boolean installed = false;
    try {
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        installed = true;

    } catch (PackageManager.NameNotFoundException e) {
        promise.reject("WALLET_NOT_FOUND", "Couldn't find wallet");
    }
    if (installed) {
        Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
        if (launchIntent != null) {
            appContext.startActivity(launchIntent);
        } else {
            promise.reject("WALLET_NOT_LAUNCHABLE", "Couldn't launch wallet");
        }
    }
}