Listening for UI notifications in Android

khatauli-9225 asked Mar 25, '21 | JarvanZhang-MSFT edited Mar 25, '21

How to keep listening to android system notifications while device is in sleep mode

Hi there, I have implemented a launcher using Xamarin Android. I would like to listen to system notifications even when the device is in sleep mode. Do I need to implement it using some kind of background service, or is there a simpler way to do it.

dotnet-android
Comment
Comment Show 0
Comment
5 |1600 characters needed characters left characters exceeded
  • Visible to all users
  • Visible to the original poster & Microsoft
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Toggle Comment visibility. Current Visibility: Visible to all users

Attachments: Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JarvanZhang-MSFT answered Mar 25, '21 | JarvanZhang-MSFT edited Mar 25, '21

Hello,​

Welcome to our Microsoft Q&A platform!

Hi, khatauli-9225. Starting in Android 8.0 (API level 26), an Android application no longer have the ability to run freely in the background. When an application moves into the background, Android will grant the app a certain amount of time to start and use services. Once that time has elapsed, the app can no longer start any services and any services that were started will be terminated.

To perform a background task for a long time, try using a foreground service instead.

Check the doc: https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/services/foreground-services

Similar issue: https://stackoverflow.com/questions/58107522/how-to-create-a-never-ending-background-service-in-xamarin-forms

Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Comment
Comment Show 0
Comment
5 |1600 characters needed characters left characters exceeded
  • Visible to all users
  • Visible to the original poster & Microsoft
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Toggle Comment visibility. Current Visibility: Visible to all users

Attachments: Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.