Venmo is not getting launched

139 views Asked by At

I have a Xamarin.Forms app where I developed a cross platform app for both iOS and Android. There, I rendered a website inside a webview. I will have a venmo button in that webview for payment. Once I click on venmo button, the venmo app that is already installed in my mobile will get launched and returns back to my app with an authorization. Everything is working fine in iOS. But in Android, when I click on venmo button in webview, venmo app is not getting launched. I have added intent filter as below in MainActivity.cs.

[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = "com.venmo")]

Also added this in AndroidManifest.xml

<queries>
<package android:name="venmo" />
<intent>
<action android:name="android.intent.action.LAUNCH" />
<data android:scheme="com.venmo" />
</intent>
</queries>
1

There are 1 answers

2
Wendy Zang - MSFT On

For Android, you could use custom renderer to invoke C# from JavaScript.

To register the action like the code below.

 webView.RegisterAction(data => DisplayAlert("Alert", "Hello " + data, "OK"));//you could use your own code to launch the app.

For more details, you could refer to the MS docs. https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview#create-the-custom-renderer-on-each-platform

You could download the code sample form GitHub for reference. https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/customrenderers-hybridwebview/

When you want to start another app in this app, you could StartActivity with the app package name.

 public Task<bool> Launch(string stringUri)
{

    Intent intent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage(stringUri);
    if (intent != null)
    {
        intent.AddFlags(ActivityFlags.NewTask);
        Forms.Context.StartActivity(intent);
        return Task.FromResult(true);
    }
    else
    {
        return Task.FromResult(true);
    }
}

For the whole code about starting an app from another app, you could refer to the thread i done before. How to launch an app from another in Xamarin forms