Search code examples
javaandroidstatusbar

How do you display big notfications with buttons?


What I am trying to do is make the big notification with at least one button ( if i'm suppose to have at least 2, i'll accept that).

public void notification() {



   notification = new NotificationCompat.Builder(this);
   notification.setStyle(new NotificationCompat.BigTextStyle(notification)
   .bigText("lololololololoolololooloololoolooolloll")
   .setBigContentTitle("Big Title")
   .setSummaryText("Big Summary"))
   //.setContentTitle("Title")
   //.setContentText("Summary")
   //.setTicker("Idk what this is really...")
   .setDefaults(Notification.DEFAULT_ALL)
   .setSmallIcon(R.drawable.holo_pressed_blue);


    //vibrates when notification comes up
    Notification note = notification.build();
   note.defaults |= Notification.DEFAULT_VIBRATE;


   manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
   manager.notify(0, notification.build());

Also if it's not to much trouble, with a small notification, how do you keep the notification in the status bar and it won't allow the user to remove it from the status bar, unless an action is made in the app?


Solution

  • You need to follow the official Tutorial.

    The CommonConstants you are struggling with are just user-defined constants:

    See https://code.google.com/p/android-source-browsing/source/browse/samples/training/notify-user/src/com/example/android/pingme/CommonConstants.java?repo=platform--development&name=jb-dev&r=fc0d593056584555189bc7f4aa36ca32ac9386b4 or https://github.com/nRike/Android-simple-notification/blob/master/src/mx/androidtitlan/simplenotification/CommonConstants.java

    Take your packageName and append ".EXTRA_MESSAGE" to it etc.