Skip to content
Advertisement

Android Foreground service without notification – how to?

I have created foreground service for notifications in my application. It’s working fine, the problem is to start the foreground service we need foreground notification which tell that your application is running like this. I don’t want this notification. How I can remove that notification without killing the service.

This is how I’m starting the foreground service.

JavaScript

Retrofit call to get notification:

JavaScript

Advertisement

Answer

Here is the implementation of Karsten Planz

You should either use the WorkManager API to implement a background sync mechanism. Then you can use the NotificationBuilder to create a “local” notifiction.

Start the Task in your main activity by this:

JavaScript

Now Create a class NotificationWorker and extends Worker. Place your startMyOwnForeground in doWork by returning Result.retry(), this will make a recursive function.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement