The provision of services in the foreground

I have a service that I want to do for the Foreground service. My service does not need to communicate with the user. The simplest example I've seen on this forum is to put this code in a service ...

Notification notification = new Notification(); startForeground(5481, notification); 

I saw a much more complex example in Commonsware pp 606, which uses Notification Builder (NotificationCompat.Builder). This and other examples require comprehensive notifications. I do not have this need.

I understand that in order for my software to be acceptable, I must at a minimum display an icon that informs the user that my service is running, and allow the user to cancel it. Also, if my service decides to stay on it, the icon should disappear. But it is so. That is all I need to do.

What should I add to the above tode to do this? thanks gary

+6
source share
1 answer

Have you read Launch Service in Foreground ?

Your notification needs an icon to display it. The system will not display notifications that do not have icons.

Reasons to use NotificationCompat.Builder: a) it supports compatibility between platforms and b) it is easier to create simple notifications with it. You can use Builder to create complex notifications, but you can also use it to create simple ones.

It is hard to say more without knowing what you are trying to do.

+7
source

All Articles