簡體   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