多个通知处理

mus*_*hid 3 notifications android android-intent android-pendingintent

我无法搞清楚Intent,PendingIntent 过滤器标志的通知.

通知正在工作,并且正在按原样生成,但问题是只有最后创建的通知才能保留Bundle Data.

我希望所有通知都保留每个通知的Bundle Data,直到用户点击它们为止.

考虑一个应用程序片刻,当不同的用户向您发送消息时,会创建新通知,当您单击任何通知时,应用程序将启动并带您进入某个特定的活动.我想要相同的东西,但是当有多个通知时,最后一个通知会将Data保留在上一个通知中,而其中包含Bundle DataIntent.

每次点击通知时,还有一个过滤器用于限制应用程序启动MainActivity的新实例.

每个通知的Notification_ID都不同.

public class AlarmSchedulingService extends IntentService {
private NotificationManager mNotificationManager;
public AlarmSchedulingService() {
    super("SchedulingService");
}

protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        sendNotification(extras.getInt(KEY_EXTRAS_NOTIFICATION_ID));
}

public void sendNotification(int NOTIFICATION_ID) {
mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(keyName, extraData); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            intent,  PendingIntent.FLAG_UPDATE_CURRENT);

    // use the right class it should be called from the where alarms are set
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this)
            .setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(titleString)
            .setStyle(
                    new NotificationCompat.BigTextStyle()
                            .bigText(messageString))
            .setDefaults(
                Notification.DEFAULT_SOUND
                | Notification.DEFAULT_LIGHTS)

            .setContentText(messageString);
        mBuilder.setContentIntent(contentIntent);

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
     }
 }
Run Code Online (Sandbox Code Playgroud)

Apu*_*kar 7

这表明:

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            intent,  PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)

您正在向所有通知提供请求代码0.0应该由每个唯一编号替换

  • 这不是通知 ID。这是“PendingIntent”的“requestCode”参数。您的建议是正确的:这需要是唯一的,但解释是错误的。 (2认同)