-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Foreground Service Demo doesn't work Anymore on Android 11 #325
Comments
This will fix the issue.
|
Even after making the change suggested by @Auto72, I am getting a NullReferenceException on the call to StartForeground |
These errors are fixed in Pull Request #346 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample link
https://docs.microsoft.com/en-us/samples/xamarin/monodroid-samples/applicationfundamentals-servicesamples-foregroundservicedemo/
Issue description
Foreground Service Demo doesn't work Anymore on Android 11
The permission "FOREGROUND_SERVICE" needs to be added to the manifest.
When you compile the project, the following warning are listed:
Build started...
1>------ Build started: Project: ForegroundServiceDemo, Configuration: Debug Any CPU ------
1>C:\Users\username\Downloads\Xamarin_Android_Foreground_Service_Sample\TimestampService.cs(32,14,32,27): warning CS0618: 'Handler.Handler()' is obsolete: 'deprecated'
1>C:\Users\username\Downloads\Xamarin_Android_Foreground_Service_Sample\TimestampService.cs(128,23,128,53): warning CS0618: 'Notification.Builder.Builder(Context?)' is obsolete: 'deprecated'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(311,5): warning XA0122: Assembly 'Xamarin.Android.Support.Annotations' is using a deprecated attribute '[assembly: Java.Interop.DoNotPackageAttribute]'. Use a newer version of this NuGet package or notify the library author.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(396,5): warning XA0125: 'ServicesDemo3.pdb' is using a deprecated debug information level.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(396,5): warning XA0125: Set the debugging information to Portable in the Visual Studio project property pages or edit the project file in a text editor and set the 'DebugType' MSBuild property to 'portable' to use the newer, cross-platform debug information level.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(396,5): warning XA0125: If this file comes from a NuGet package, update to a newer version of the NuGet package or notify the library author.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
So obsolete methods are used.
Steps to reproduce the issue
What's the expected result?
See the example working.
What's the actual result?
If get the following error:
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: com.xamarin.xample.foregroundservicedemo, PID: 8524
[AndroidRuntime] android.app.RemoteServiceException: Bad notification for startForeground
[AndroidRuntime] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2188)
[AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:107)
[AndroidRuntime] at android.os.Looper.loop(Looper.java:237)
[AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:8167)
[AndroidRuntime] at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
Android.Util.AndroidRuntimeException: 'Bad notification for startForeground'
Additional details / screenshot (Optional)
The text was updated successfully, but these errors were encountered: