[Xamarin.Android.Tools.AndroidSdk] Check all <intent-filter/>s#214
Merged
[Xamarin.Android.Tools.AndroidSdk] Check all <intent-filter/>s#214
Conversation
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
jpobst
approved these changes
Aug 4, 2023
jonpryor
pushed a commit
to dotnet/android
that referenced
this pull request
Aug 17, 2023
Context: https://developercommunity.visualstudio.com/t/Cannot-deploy-to-Android-emulators-and-d/10428163 Changes: dotnet/android-tools@57be026...52f0866 * dotnet/android-tools@52f0866: [Xamarin.Android.Tools.AndroidSdk] Check all <intent-filter/>s (dotnet/android-tools#214) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
jonpryor
pushed a commit
to dotnet/java-interop
that referenced
this pull request
Sep 11, 2023
Changes: dotnet/android-tools@3cee10b...9c50a2d * dotnet/android-tools@9c50a2d: [build] set `$(DisableTransitiveFrameworkReferenceDownloads)`=true (dotnet/android-tools#216) * dotnet/android-tools@52f0866: [Xamarin.Android.Tools.AndroidSdk] Check all <intent-filter/>s (dotnet/android-tools#214) * dotnet/android-tools@57be026: [Xamarin.Android.Tools.AndroidSdk] Update SDK component for API-34 (dotnet/android-tools#211) * dotnet/android-tools@0a9ea47: [Xamarin.Android.Tools.AndroidSdk] Add API-34 to KnownVersions (dotnet/android-tools#212) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/>and related elements withinAndroidManifest.xmlcan have multiple<intent-filter/>s specified. Android does not require that<intent-filter/>s be listed in any particular order.However, Visual Studio does care about the order (?!)!
If the
[IntentFilter]withAndroid.Content.Intent.ActionMainis 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 ofandroid.intent.category.LAUNCHER.Update
AndroidAppManifest.GetLaunchableActivities()so that all<intent-filter/>elements are checked for the.LAUNCHERcategory.Workaround: Specify the
[IntentFilter]withIntent.ActionMainfirst: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.