繁体   English   中英

Android:如何连续显示2条通知

[英]Android: How do I show 2 notifications in a row

以下方法使用不同的name参数调用了两次,但是我的设备上仅显示1条通知(最后一条)。 我认为将唯一的请求模式参数与name.hashCode()一起放在PendingIntent.getActivity()内是可行的,但这并不能解决问题。 因此,如何更改此方法以使我的设备连续显示2条通知,而不仅仅是最后一条?

private void showNotification(String name, String sub) {
        Intent intent = new Intent(activity.getApplicationContext(),
                FragmentTabsPager.class);
        PendingIntent pIntent = PendingIntent.getActivity(
                activity.getApplicationContext(), name.hashCode(), intent, 0);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                activity.getApplicationContext());  
        builder.setContentTitle("Hello world"
                ).setContentText(name+" from "+sub)
                .setSmallIcon(R.drawable.icon).setContentIntent(pIntent)
                .getNotification();
        NotificationManager notificationManager = (NotificationManager) activity
                .getApplicationContext().getSystemService(
                        Context.NOTIFICATION_SERVICE);
        Notification notification = builder.getNotification();      
        notification.flags |= Notification.FLAG_AUTO_CANCEL;        
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;      
        notificationManager.notify(0, notification);
    }

notify()的第一个参数是notify()的ID。 如果您希望不同的Notification出现在屏幕上,则必须有所不同。 如果使用相同的ID两次调用notify() ,则将替换而不是添加Notification

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM