Jacob Cohen
Jacob Cohen

Reputation: 1272

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);
}

Upvotes: 11

Views: 19465

Answers (2)

CarbonAssassin
CarbonAssassin

Reputation: 875

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

Upvotes: 27

Vijju
Vijju

Reputation: 3508

ok add this in your code :

n.flags |= Notification.FLAG_NO_CLEAR;

Upvotes: 7

Related Questions