android通知显示在通知栏上

android通知显示在通知栏上,android,notifications,Android,Notifications,我想通过安卓系统来收听nofication display事件,这意味着我想知道nofication是否已经显示在手机的通知栏上,以及如何获得目标?谢谢。这是通知通知的代码 private void generateNotification(Context context) { long when = System.currentTimeMillis(); // notifytime = when; Intent noti

我想通过安卓系统来收听nofication display事件,这意味着我想知道nofication是否已经显示在手机的通知栏上,以及如何获得目标?谢谢。

这是通知通知的代码

private void generateNotification(Context context) {

            long when = System.currentTimeMillis();
            // notifytime = when;
            Intent notifyIntent = new Intent(context,
                    com.example.RegisterActivity.class);

            notifyIntent.putExtra("address", "Hello World");

            notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                    notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(
                    context).setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("Hello World").setContentIntent(pendingIntent)
                    .setAutoCancel(true)
                    .setDefaults(Notification.DEFAULT_SOUND).setWhen(when);

            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            builder.setAutoCancel(true);
            notificationManager.notify((int) when, builder.build());
        }
在那里,我们可以放置通知id,并在NotificationManager中检查该通知id