I am trying to use .Net MAUI Project template to build an Android App to Emulate in Pixel 4 - API33 using Android Device Manager. I tried many things in MainPage.xaml.cs to use the button given in the example code for an additional function. I need the button to Open the Google Wallet App if it is installed. I used many different codes and ended up with following error at the end.
System.UriFormatException: 'Invalid URI: The format of the URI could not be determined.'
I used following code block:
using Android.Content;
using Android.Net;
namespace <MyProjectName>;
public partial class MainPage : ContentPage
{
int count = 0;
public MainPage()
{
InitializeComponent();
}
private async void OnCounterClicked(object sender, EventArgs e)
{
count++;
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
SemanticScreenReader.Announce(CounterBtn.Text);
string packageName = "com.google.android.apps.walletnfcrel";
if (await Launcher.CanOpenAsync(packageName))
{
try
{
Intent intent = new Intent(Intent.ActionView);
intent.SetData(Android.Net.Uri.Parse("market://details?id=" + packageName));
intent.SetClassName("com.android.vending", "com.android.vending.AssetBrowserActivity");
intent.AddFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(intent);
}
catch (Exception ex)
{
Console.WriteLine($"Unable to Open Google Wallet: {ex.Message} ");
}
}
else
{
// Google Wallet app is not installed, display an error message or take alternative action
Console.WriteLine("Google Wallet app is not installed.");
}
}
}