2
votes

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

2 Answers

0
votes

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. 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'.

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. Hope this helps others.

0
votes

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

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