-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a Connectivity.ConnectivityChanged handler throw an exception on Android 14 #17861
Comments
There is a breaking change for Android API 34 that requires setting the RecieverFlags. I believe if we update to this new API, Application.Context.RegisterReceiver(conectivityReceiver, filter, ReceiverFlags.NotExported); it would work again... the problem being, it's only in the Android 34 dlls (In that, it's in the preprocessor defs to only be compiled for Android 34, and as far as I can tell can't be referenced on early versions. I'm not sure if MAUI ships multiple editions for essentials that target specific Android versions like that. @jonpryor @jpobst do ya'll know how to access this API in Essentials? Or did I misunderstand the problem? |
Context: dotnet/android@d9e4407 This new API will only be available for projects targeting .NET 8+. If you want to be able to call this API for earlier projects you will need to call the incorrectly enumified version that has existed for many years: You can cast the enums as needed: Application.Content.RegisteredReceiver(conectivityReceiver, filter, (ActivityFlags)ReceiverFlags.NotExported); |
Verified this on Visual Studio Enterprise 17.8.0 Preview 2.0(8.0.0-rc.1.9171). Repro on Android 14.0-API34 with below Project: |
verified the issue exists on Xamarin forms as well |
We also face this issue. Is there any chance to temporary avoid this exception? |
@albertruff You can temporary avoid this exception by setting the Android targetSdkVersion to 33 instead of 34. |
@dondestas Thank you. It works |
This needs to be updated in other areas too. We need to do an audit of our code base to see where it's implicated and determine the correct values to use. |
Got this crash today after update to .net 8 |
I'm getting this on a project after .net 8 upgrade, specifically during this call:
|
EDIT: ah its in nightly builds now... zzzz. i'll wait :P |
This comment was marked as off-topic.
This comment was marked as off-topic.
@dylix closing PRs/issues only when something is released is a pretty hard thing to administer. Whenever something is merged we consider it fixed but it is pending release. Keep you eye on the release notes. |
+1 |
Commenting your comment for the same reason |
+1
|
+1 |
Connectivity Change event does not fire in android 34 and also does not fire in iOS |
@gabsamples6 @mikeluken Note: Reference link: https://developer.android.com/about/versions/14/behavior-changes-14#runtime-receivers-exported |
Thanks for the comment. However, I do not fully understand your post. I don't have a broadcast receiver to register. In App.xaml.cs, I am just specifying:
In Android 13, this works. In Android 14, Can you please provide a full example of how you got this to work? It appears as though a fix was already attempted for this: However, I am running the latest nightly builds and this still does not work. Note: I also added this to my MainActivity.OnCreate(...):
It had no effect. |
@mikeluken
Creat in MainActivity:
Then in OnStart() of MainActivity:
I use this temporary solution until MAUI makes a correction |
Thanks. Yes I was able to get broadcast receivers to work. I was however trying to point out the fact that ConnectivityChanged event in dotnet Maui doesn't work for Android 14. |
The only hope we have now is that #19949 that you raised @mikeluken gets fixed.. and from what I can see is no part of any milestone.. which you know what that means |
Adding the obligatory comment so I'll know when I can target Android 14 |
hi @jfversluis - Since Essentials is part of Maui now, is this issue going to be fixed? or a new issue should be created since this one is closed. |
+1 to keep it on my radar |
@mikeluken Thank you! Can you please open a new issue for this? It'll be easier for us to track it. Thanks!!! |
Just adding my two cents, this intent
If I set this in the constructor of that class, everything works fine: connectivityIntent.SetPackage(AppInfo.PackageName); |
I am using version 8.0.7 but the event ConnectivityChanged still doesn't fire if I turn off Wifi or turn on Wife on my Android phone. At least it doesn't crash the whole application anymore. Do you have the same issue or does it work for you now? |
Same here it's not working for me either. Please FIX MS. |
Test on
The app will crash on the same exception in the initial stage
|
Not working on Android 14. |
@ilmian Maybe you wanna open a new issue, since this one is closed |
Description
When adding a Connectivity.ConnectivityChanged handler, the following exception is thrown on an Android 14 device, when the targetSdkVersion is 34 (the default with new Maui app) an when run on Android 14:
Steps to Reproduce
Connectivity.ConnectivityChanged += (sender, e) => { };
Link to public reproduction project repository
No response
Version with bug
8.0.0-rc.1.9171
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 14
Did you find any workaround?
Change the target Android version to 13. The code will work on Android 14 then.
Relevant log output
The text was updated successfully, but these errors were encountered: