-2
私はアンドロイドの通知に取り組んでおり、うまくいきます。私が持っている問題は、manager.cancel()
またはmanager.cancel(id)
で通知をキャンセルし、別の通知が届いたときに、以前にキャンセルされた通知も表示されています。以下は私のコードです。Android通知をキャンセル
private void sendNotification(String msg) {
Intent intent = null;
if(REQUEST_ID != null)
{
intent = new Intent(ctx, PayApp.class)
.putExtra("FRAGMENT", "Transactions")
.putExtra("REQUEST_ID", REQUEST_ID)
.putExtra("NOTIFICATIONID", NOTIFICATION_ID);
}
else
{
intent = new Intent(ctx, PayApp.class).putExtra("FRAGMENT", "Transactions");
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mNotificationManager = (NotificationManager)
ctx.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
intent, PendingIntent.FLAG_ONE_SHOT);
counter = notificationCounter.incrementAndGet();
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx)
.setSmallIcon(R.mipmap.ic_launcher)
.setSound(defaultSoundUri)
.setAutoCancel(true).setNumber(counter)
.setContentText(msg)
.setPriority(Notification.PRIORITY_MAX)
.setColor(ContextCompat.getColor(ctx, R.color.intel_blue_deeper))
.setContentTitle("Xente Agency");
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(mBuilder);
inboxStyle.setBigContentTitle("Xente Agency");
messageList.add(msg);
for(String m : messageList)
{
inboxStyle.addLine(m);
}
mBuilder.setStyle(inboxStyle);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
そして、私はそれをクリック
if(getArguments() != null)
{
REQUEST_ID = getArguments().getString("REQUEST_ID");
NOTIFICATION_ID = getArguments().getInt("NOTIFICATIONID", 0);
if(NOTIFICATION_ID == 1)
{
NotificationManager manager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
//this also does not work
//manager.cancel(NOTIFICATION_ID)
manager.cancelAll();
NOTIFICATION_ID = 0;
}
}
おかげで申し訳ありませんが、それは私のミスだ、そのようなPendingIntent.FLAG_AUTO_CANCEL –
を投票します。この 'FLAG_UPDATE_CURRENT'フラグを試してください。 –
@odichdanielがない私はそれを試してみましょうし、あなたの答え – kimkevin