我有 2 个应用程序( A 和 B )使用 Xamarin.Forms 开发。我需要从应用程序 B 打开应用程序 A。
我按照这个线程尝试过如下:
在视图中
var appname = @"otherappId";
var result = await DependencyService.Get<IAppHandler>().LaunchApp(appname);
Run Code Online (Sandbox Code Playgroud)
界面
public interface IAppHandler
{
Task<bool> LaunchApp(string uri);
}
Run Code Online (Sandbox Code Playgroud)
安卓
[Activity(Label = "OpenAppAndroid")]
public class OpenAppAndroid : Activity, IAppHandler
{
public Task<bool> LaunchApp(string uri)
{
bool result = false;
try
{
var aUri = Android.Net.Uri.Parse(uri.ToString());
var intent = new Intent(Intent.ActionView, aUri);
Xamarin.Forms.Forms.Context.StartActivity(intent);
result = true;
}
catch (ActivityNotFoundException)
{
result = false;
}
return Task.FromResult(result); …Run Code Online (Sandbox Code Playgroud)