繁体   English   中英

取消Android推送通知

[英]Dismiss Android push Notifications

有关推送通知的一些问题。 当我按下应用程序中的所有通知之一时,该如何分散它们? 另外...如果我启动应用程序(而不是从提名中),如何取消提名?

这是我从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.app.NotificationManager.cancelAll()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM