正如标题所述,我正在尝试从另一个(本机)Android应用程序和
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
.
下面是我正在进行的调用(基于URI的调用——可能是问题所在?)在本机Android应用程序中:
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);
}