I need to show a notification in status bar even if the app is killed or swiped from tray. I have use onGoing(true)
& Flag.onGoing_event
. It works nicely in some phones but not in all phones.what to do? I need something like the below picture.
private void showNotificationBarState(String title, String body) {
int mNotificationId = 5;
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.avatar_profile)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setOngoing(true);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
notificationBuilder.getNotification().flags |= Notification.FLAG_ONGOING_EVENT;
notificationBuilder.getNotification().flags |= Notification.FLAG_FOREGROUND_SERVICE;
assert notificationManager != null;
notificationManager.notify(mNotificationId /* ID of notification */, notificationBuilder.build());
}