如标题所述,我正在尝试从另一个(本机)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);
}
答案 0 :(得分:1)
您已经混淆了URL的HOST和SCHEME。您的网址:
"deeplinktest://MyAppDidComplete/somedata"
细分如下:
您的IntentFilter
设置为匹配:
您应该修改一个或另一个,以便它们匹配。