简体   繁体   English

在“添加付款方式”屏幕上启动 Google Pay

[英]Launch Google Pay on "Add Payment Method" Screen

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.现在,我希望能够添加一个按钮,该按钮将启动 Google Pay应用程序以允许用户添加付款方式。

I've seen code how to launch Google Play.我看过如何启动 Google Play 的代码。 I am hoping it is similar but with a different URI.我希望它是相似的,但具有不同的 URI。

Could anyone help out please.任何人都可以请帮忙。

OK - not completely there yet but it did strike me that I just need to launch an app.好的 - 还没有完全到位,但确实让我觉得我只需要启动一个应用程序。 So, to that end I connected my phone to my PC adn ran the Android device monitor.因此,为此,我将手机连接到 PC 并运行 Android 设备监视器。 LAunched Google Pay on my phone and sorted through the wheat and chaff to find the package name which currently is 'com.google.android.apps.walletnfcrel'.在我的手机上启动 Google Pay 并通过小麦和谷壳进行分类以找到当前为“com.google.android.apps.walletnfcrel”的包名称。

A little more googling and I found a way to test if the app is installed......多一点谷歌搜索,我找到了一种测试应用程序是否安装的方法......

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

...and then if it is installed I can fire it up as follows..... ...然后如果它已安装,我可以按如下方式启动它.....

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

For now I am happy with that.....other things to do but I will try at a later date to actually trigger the add payment method process.现在我很高兴......其他事情要做,但我会在以后尝试实际触发添加付款方式过程。

Thanks to other postings on SO.感谢关于 SO 的其他帖子。 Hope this helps others.希望这对其他人有帮助。

I came up with this solution in our app.我在我们的应用程序中提出了这个解决方案。 The app is built with React Native and I implemented a button which calls a method in a native Java module (if you are wondering why I use a promise here):该应用程序使用 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");
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM