I am trying to make my Service
running in foreground. I tried to use this example (please look for the section "Running a Service in the Foreground"), but startForeground()
does not actually show my notification. And no exceptions is thrown. To make it shown, I need to use NotificationManager
like here explained. With NotificationManager
my notification works, but i'm not sure that my Service
is foreground after this "silent" call to startForeground()
.
What can be wrong?
EDIT: I just tested this sample project that should demonstrate startForeground()
, but it does not work! I use API v7.0, I tested it both on emulator and real device (SE Xperia Neo). Notification does not appear.
EDIT2: if i try to call setForeground()
then i got a warning setForeground: ignoring old API call
.
I also tried to use startForegroundCompat()
as described here, but effect is absolutelly the same. I check if my service is foreground using ActivityManager.RunningServiceInfo
as described here, and I see that my service is not foreground.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…