You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Xamarin.Android.Tools.AndroidSdk] Check all <intent-filter/>s (#214)
Context: https://developercommunity.visualstudio.com/t/Cannot-deploy-to-Android-emulators-and-d/10428163
Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1863835
Context: https://developer.android.com/guide/components/intents-filters
The [`<activity/>`][0] and related elements within
`AndroidManifest.xml` can have multiple [`<intent-filter/>`][1]s
specified. Android does not require that `<intent-filter/>`s be
listed in any particular order.
However, Visual Studio *does* care about the order (?!)!
[Activity(Exported = true, Label = "@string/app_name", MainLauncher = true)]
[IntentFilter(
new[] { Android.Content.Intent.ActionView },
Categories = new[] {
Android.Content.Intent.CategoryDefault,
Android.Content.Intent.CategoryBrowsable,
}
)]
[IntentFilter(
new[] { Android.Content.Intent.ActionMain },
Categories = new[] {
Android.Content.Intent.CategoryLauncher,
Android.Content.Intent.CategoryLeanbackLauncher,
}
)]
public partial class MainActivity : Activity {}
If the `[IntentFilter]` with `Android.Content.Intent.ActionMain`
is *not* first, then Visual Studio does not consider this Activity
to be a launchable activity.
The reason for this is, in part, because
`AndroidAppManifest.GetLaunchableActivities()` only looked at the
*first* `<intent-filter/>` to see if it had the category of
`android.intent.category.LAUNCHER`.
Update `AndroidAppManifest.GetLaunchableActivities()` so that *all*
`<intent-filter/>` elements are checked for the
`.LAUNCHER` category.
**Workaround**: Specify the `[IntentFilter]` with `Intent.ActionMain`
first:
[Activity(Exported = true, Label = "@string/app_name", MainLauncher = true)]
[IntentFilter(
new[] { Android.Content.Intent.ActionMain },
Categories = new[] {
Android.Content.Intent.CategoryLauncher,
Android.Content.Intent.CategoryLeanbackLauncher,
}
)]
[IntentFilter(
new[] { Android.Content.Intent.ActionView },
Categories = new[] {
Android.Content.Intent.CategoryDefault,
Android.Content.Intent.CategoryBrowsable,
}
)]
public partial class MainActivity : Activity {}
Note: this change, in and of itself, may not be sufficient to fix
Visual Studio, as there are a few other places that have the same
"only check the first `<intent-filter/>`" bug.
[0]: https://developer.android.com/guide/topics/manifest/activity-element
[1]: https://developer.android.com/guide/topics/manifest/intent-filter-element
0 commit comments