你如何显示带有按钮的大通知?

How do you display big notfications with buttons?

我想做的是用至少一个按钮发出重要通知(如果我假设至少有 2 个,我会接受)。

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

此外,如果不是很麻烦,通过一个小通知,您如何将通知保留在状态栏中,并且不允许用户将其从状态栏中删除,除非在应用程序?

您需要遵循 official Tutorial.

您遇到的 CommonConstants 只是用户定义的常量:

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

获取您的 packageName 并在其后附加“.EXTRA_MESSAGE”等