Vincent
Vincent

Reputation: 175

How to fix icon in Android status bar

I have the code below that creates an icon on the Android status bar.

Context context = getApplicationContext();
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.ic_launcher)
    .setContentTitle(getString(R.string.app_name))
    .setContentText("Live Tracking");

Intent intent = new Intent( context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent pIntent = PendingIntent.getActivity(context, mID , intent, 0);
builder.setContentIntent(pIntent);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

Notification notif = builder.build();
mNotificationManager.notify(mID, notif);

Is there a way to prevent the icon from being removed when the user presses the "wipe out every notifications" button ?

Many thanks for your help. Best regards, Vincent.

Upvotes: 0

Views: 749

Answers (1)

tyczj
tyczj

Reputation: 73996

add setOngoing(true) to your notification builder. That persists the notification so you have to make sure you remove it yourself

Upvotes: 1

Related Questions