0

My app uses a foreground service notification that works just fine on 6.0 and below. I use this answer for hiding the icon from the status bar and lock screen, in certain cases (my app has two modes, one "background" mode where the app does not need to permanently notify the user, and one "high alert" mode where I use maximum priority for this notification).

This, as I said, works perfectly well on Android 6.0 and below. However on Nougat, even though my app targets API level 24 (minimum is API level 17) and uses the latest release from everything, this notification is displayed as a normal one.

I've searched for possible solutions but due to the relative freshness of 7.0, there's not much information. I've noticed that some apps do manage to show their notifications as minimum priority even on 7.0 (one of these is AccuBattery).

I use the following code to create the notification:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(getString(R.string.app_name));
builder.setOngoing(true);
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setSmallIcon(R.drawable.ic_stat_onesignal_default);
builder.setColor(getResources().getColor(R.color.notification_color));

Intent alertIntent = new Intent(this, SplashActivity.class);
alertIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, alertIntent, 0);
builder.setContentIntent(pendingIntent);
switch (mode) {
    case ALERT:
        builder.setContentText("Alert is active");
        builder.setPriority(Notification.PRIORITY_MAX);
        break;
    case BACKGROUND:
    default:
        builder.setContentText("Background service running");
        builder.setPriority(Notification.PRIORITY_MIN);
        break;
}
Community
  • 1
  • 1
fonix232
  • 2,132
  • 6
  • 39
  • 69

0 Answers0