我正在测试可堆叠通知(Stacking Notifications文章).
我发现在某些情况下,notify()在运行android 4.X KitKat的设备中调用后,通知未显示.
为了简单地解决问题,我创建了这个模拟通知的代码(button1)和带有摘要的第二个通知(button2)
private final static int NOTIFICATION_ID_A=6;
private final static int NOTIFICATION_ID_B = 7;
private final static int NOTIFICATION_ID_SUMMARY = 8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showNotif(NOTIFICATION_ID_A,false);
}
});
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showNotif(NOTIFICATION_ID_B,false);
showNotif(NOTIFICATION_ID_SUMMARY,true);
}
});
}
private void showNotif(int notificationId,boolean groupSummary) {
CharSequence title="Title "+notificationId;
CharSequence message="Message "+notificationId;
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this); …Run Code Online (Sandbox Code Playgroud)