从 Xamarin 中的应用程序启动应用程序

Launch app from app in Xamarin

我用 Xamarin 编写了两个应用程序:CallerApp 和 CalleeApp。如果单击 CallerApp 中的按钮,CalleeApp 应该启动(如果尚未启动)并变得可见。

在 CalleeApp 的 MainActivity 之上,我定义了这样的意图:

 [IntentFilter(new [] { Intent.ActionView }, DataScheme="abcdef", Categories=new[] { Intent.CategoryDefault, Intent.CategoryBrowsable })]
 public class MainActivity : global::Xamarin.Forms.Platform.FormsApplicationActivity
 {
      ...
 }

在 CallerApp 中,单击按钮时,我执行:

 var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(abcdef://));
 Forms.Context.StartActivity(intent);

然后我 运行 CalleeApp,然后在设备上部署并启动。 然后我 运行 CallerApp,然后部署在设备上并启动。 如果我然后单击该按钮,我会收到消息:"No apps can perform this action".

有人知道我做错了什么吗?

注意:如果我尝试像 http://developer.xamarin.com/recipes/android/fundamentals/intent/launch_the_map_application/ 中的示例那样启动地图应用程序,我会收到相同的消息。

好吧,我刚刚让它工作了,但不是通过更改代码。开发机当前日期时间错误,改正后就可以运行了!

我必须使用一个 Intent 来解决,这个 Intent 尝试使用 PackageManager class 启动你想要的包,简单地说:

Intent intent = PackageManager.GetLaunchIntentForPackage("com.company_name.app_name");
StartActivity(intent);

不要忘记将“com.company_name.app_name”替换为您要 运行 的应用程序包的名称。如果未安装应用程序包,则会引发异常,然后您可以要求用户安装应用程序,打开 Play 商店,然后就可以了。