Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to create a Permanent Notification

I have created a notification in my "onCreate" activity method.

Everything runs smoothly, only that you can close it by pressing the "delete all" button.

How do I make this notification perma? as in it should just be more of an info rather than a notification..

This is my current code:

    private void showNotification() {
    // TODO Auto-generated method stub
    nMN = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification n  = new Notification.Builder(this)
    .setContentTitle("Whip And Weep")
    .setContentText("Whip is On!")
    .setSmallIcon(R.drawable.ic_launcher)
    .build();
    nMN.notify(NOTIFICATION_ID, n);
}
like image 441
Jacob Cohen Avatar asked Mar 21 '14 10:03

Jacob Cohen


People also ask

What is permanent notification in Android?

A permanent notification is a (usually silent) alert displayed by certain apps on your Android smartphone or tablet at all times to let you know they're running in the background.

What is a non removable notification Android?

When an app needs to be absolutely sure it won't be cleared from RAM by Android's memory management system, it posts a persistent, ongoing notification. Another time you'll encounter non-removable alerts is when your phone or carrier really wants you to do something, like apply an update.


1 Answers

On your notification builder use .setOngoing(true). This will prevent the user from removing your notification.

See the Notification Builder Documentation for more info: http://developer.android.com/reference/android/app/Notification.Builder.html#setOngoing%28boolean%29

like image 196
CarbonAssassin Avatar answered Nov 15 '22 15:11

CarbonAssassin