0

以下のメソッドは異なるパラメーターで 2 回呼び出されていnameますが、デバイスには 1 つの通知 (最後の通知) しか表示されません。PendingIntent.getActivity()独自のリクエスト モード パラメータをwith内に入れるname.hashCode()とうまくいくと思いましたが、問題は解決しませんでした。では、このメソッドを変更して、デバイスに最後の通知だけでなく 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);
    }
4

1 に答える 1

0

の最初のパラメーターnotify()は、通知の ID です。Notification画面に異なる を表示する場合は、異なる必要があります。notify()同じ ID で 2 回呼び出すとNotification、 が追加されずに置き換えられます。

于 2013-03-10T17:38:18.070 に答える