我想在点击后清除通知。我的代码如下。谁能说明我错在哪里?
公共类Notification1扩展了Activity {
private static final int MY_NOTIFICATION_ID=1;
@SuppressWarnings("deprecation")
Notification1(Context c)
{
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(c)
.setSmallIcon(R.drawable.smil)
.setContentTitle("UnHabit")
.setAutoCancel(true)
.setContentText("Continue with the set profile?");
Intent resultIntent = new Intent(c, MainActivity.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
c,
0,
resultIntent,
0
);
//mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
mBuilder.setContentIntent(resultPendingIntent);
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) c.getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
}
答案 0 :(得分:0)
编辑: 试试这个
PendingIntent resultPendingIntent = PendingIntent.getActivity(c, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT))
另见此链接
Android remove notification(created by mNotifyBuilder) on click