从另一个Android应用程序启动Xamarin Android应用程序

时间:2019-01-15 04:21:27

标签: android android-intent xamarin.android

如标题所述,我正在尝试从另一个(本机)Android应用程序启动一个Android Xamarin应用程序,并且packageManager.queryIntentActivities查询失败。因此,我可能在Android应用程序方面或在Xamarin方面都做错了。

这是Xamarin端的类定义:

using Android.OS;

namespace DeepLinkTest.Droid
{
    [Activity(Label = "DeepLinkTest", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    [IntentFilter(new[] { Android.Content.Intent.ActionView },
        DataScheme = "*",
        DataHost = "deeplinktest",
        DataPath = "MyAppDidComplete",
        Categories = new[] { Android.Content.Intent.CategoryDefault })]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }
    }
}

从我读到的intent来看,是MainActivity上方的地方。

这是我在本地Android应用中拨打的电话(基于uri的电话-也许是问题所在?)

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deeplinktest://MyAppDidComplete/somedata"));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // Verify it resolves
            PackageManager packageManager = getPackageManager();
            List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
            boolean isIntentSafe = activities.size() > 0;

            // Start an activity if it's safe
            if (isIntentSafe) {
                startActivity(intent);
            }

1 个答案:

答案 0 :(得分:1)

您已经混淆了URL的HOST和SCHEME。您的网址:

"deeplinktest://MyAppDidComplete/somedata"

细分如下:

  • 方案:“ deeplinktest”
  • 主机:“ MyAppDidComplete”
  • 路径:“ / somedata”

您的IntentFilter设置为匹配:

  • scheme =“ *”
  • host =“ deeplinktest”
  • path =“ MyAppDidComplete”

您应该修改一个或另一个,以便它们匹配。