gpt4 book ai didi

android - 关闭 Android 推送通知

转载 作者:行者123 更新时间:2023-11-30 03:06:43 24 4
gpt4 key购买 nike

关于推送通知的一些问题。当我按下其中一个通知时,如何关闭我的应用程序的所有通知?另外...如果我启动应用程序(不是来自通知),我该如何关闭通知?

这是我从 GcmIntentService 类发送通知的方式(如果有帮助的话)。

private void sendNotification(Bundle extras) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);

NOTIFICATION_ID = Integer.parseInt(extras.getString("id"));

Intent in = new Intent(this, PushActivity.class);
in.putExtras(extras);
in.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
String msg = extras.getString("msj");

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

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("MY TITLE")
.setAutoCancel(true)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);

mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

最佳答案

我不确定您发出的通知是否针对同一事件,如果是这样,您可以像 Gmail 一样在收到第二封或第三封电子邮件时执行所谓的“堆叠通知”。这一切都在一个通知中,因此将作为一个通知消失。这仅兼容 4.1 以上版本。

这是 Google 随堆叠一起提供的代码。这有什么帮助吗?

mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Sets an ID for the notification, so it can be updated
int notifyID = 1;
mNotifyBuilder = new NotificationCompat.Builder(this)
.setContentTitle("New Message")
.setContentText("You've received new messages.")
.setSmallIcon(R.drawable.ic_notify_status)
numMessages = 0;
// Start of a loop that processes data and then notifies the user
...
mNotifyBuilder.setContentText(currentText)
.setNumber(++numMessages);
// Because the ID remains unchanged, the existing notification is
// updated.
mNotificationManager.notify(
notifyID,
mNotifyBuilder.build());

关于android - 关闭 Android 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21695614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com