I'm using the following code:
private void startForeground(boolean isActive) {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(isActive ? R.string.title_agent_active : R.string.title_agent_inactive))
.setContentIntent(pendingIntent)
.build();
startForeground(1, notification);
}
and
@Override
protected void onHandleIntent(Intent intent) {
startForeground(true);
...
With this code notification does not appear.
But if I replace startForeground(...) with NotificationManager.notify(...) — it shows the notification, so, I think, that at least notification building code is ok.
Where could be the problem?