我的通知应该在刷卡时解除,因为它不是正在进行的,但它不会,只有当你点击它时才会解除。这是通知代码:
Intent resultIntent = new Intent(this, ArticleView.class);
resultIntent.putExtra(NOTIFY_MESSAGE, articles[0]);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ArticleView.class);
/* Adds the Intent that starts the Activity to the top of the stack */
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
Notification mBuilder = new Notification.Builder(this)
.setContentTitle(getString(R.string.new_blog_post))
.setContentText(articles[0][0])
.setTicker(getString(R.string.new_blog_post))
.setSmallIcon(R.drawable.icon)
.setStyle(new Notification.BigTextStyle()
.bigText(articles[0][0] + "\n" + articles[0][1] + "\n" + articles[0][2]))
.setPriority((Notification.PRIORITY_DEFAULT))
.setAutoCancel(true)
.setLights(0xff00ff00, 300, 300)
.setSound(Uri.parse(SettingsActivity.getRingtone(this)))
.setContentIntent(resultPendingIntent)
.setOngoing(false)
.build();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder.flags |= Notification.FLAG_SHOW_LIGHTS;
mBuilder.flags |= Notification.FLAG_AUTO_CANCEL;
if (SettingsActivity.getVibrate(this))
mBuilder.flags |= Notification.DEFAULT_VIBRATE;
mNotificationManager.notify(NOTIFICATION_ID, mBuilder);
答案 0 :(得分:2)
尝试删除这些行:
if (SettingsActivity.getVibrate(this))
mBuilder.flags |= Notification.DEFAULT_VIBRATE;
Notification.DEFAULT_VIBRATE == 2 == Notification.FLAG_ONGOING_EVENT
(见这里:http://developer.android.com/reference/android/app/Notification.html#DEFAULT_VIBRATE)