Commit 52f0866
authored
[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-element1 parent 57be026 commit 52f0866
File tree
3 files changed
+22
-2
lines changed- src/Xamarin.Android.Tools.AndroidSdk
- tests/Xamarin.Android.Tools.AndroidSdk-Tests
- Resources
3 files changed
+22
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
327 | | - | |
| 326 | + | |
328 | 327 | | |
329 | 328 | | |
330 | 329 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
48 | 58 | | |
49 | 59 | | |
50 | 60 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
25 | 36 | | |
26 | 37 | | |
27 | 38 | | |
| |||
0 commit comments