我的android studio项目中有一段代码:
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
// .setSmallIcon(R.drawable.ic_stat_gcm)
.setContentTitle("New updates from StoriesCity!")
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
它工作正常,我看到了通知,但是当我点击它时它不会消失..
也许是因为我正在使用.notify? 请帮我修改代码,以便在点击时显示失败。
我是初学者:)
答案 0 :(得分:2)
答案 1 :(得分:0)
设置标记FLAG_CANCEL_CURRENT
而不是0
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), PendingIntent.FLAG_CANCEL_CURRENT);
另外
.setAoutoCancel(true)