【问题标题】:How do I remove the notification if clicked?如果单击,如何删除通知?
【发布时间】:2015-10-31 14:54:01
【问题描述】:

所以我想知道如何在用户单击通知中心后删除待处理的通知。这是我的广播接收器:

public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Intent startServiceIntent = new Intent(context, BackgroundChecks.class);
    startServiceIntent.putExtra("notificationActivityAmtsblatt", AmtsblattActivity.class.getName());
    startServiceIntent.putExtra("notificationActivityAmtstafel", AmtsblattActivity.class.getName());
    context.startService(startServiceIntent);
}
}

我可以把它放在那个 BCReceiver 的某个地方吗? 谢谢

【问题讨论】:

  • @ing0 因为我是一名编程初学者,所以您发布的链接对我来说并不是很容易理解。我很抱歉重新发布

标签: android notifications broadcast receiver


【解决方案1】:

最简单的解决方案是在构建通知时将通知的 autoCancel 属性设置为 true,例如:

yourNotification.setAutoCancel(true);

但是如果你想在你的 BCReceiver 中关闭通知,你可以使用 NotificationManager 的 cancel(int notificationId) 方法,比如:

NotificationManager mNotifyMgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.cancel(youNotificationId);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    • 2011-07-05
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多