2014-09-19 159 views
1

我可以通过点击通知删除此通知吗?如何在点击通知时删除通知android

当使用setAutoCancel(true)单击此通知时,我可以取消通知。

但点击通知后不清楚通知。

private void sendNotification(String msg, Bundle extras) { 
    notificationManager = (NotificationManager) this 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent intent; 
    if (extras != null) { 
     intent = new Intent(this, MessageConversationActivity.class); 
     intent.putExtra("sender_id", extras.get("sender_id").toString()); 
     intent.putExtra("receiver_id", Application.ACTIVE_USER.getUser_id()); 
     intent.putExtra("gender", extras.get("gender").toString()); 
     intent.putExtra("profile_picture", extras.get("profile_picture") 
       .toString()); 
     intent.putExtra("username", extras.get("username").toString()); 
    } else { 
     intent = new Intent(this, MainActivity.class); 
    } 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
      intent, 0); 

    String app_name = getString(R.string.app_name); 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
      this).setSmallIcon(R.drawable.app_icon) 
      .setContentTitle(app_name) 
      .setAutoCancel(true) 
      .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) 
      .setContentText(msg); 

    builder.setContentIntent(contentIntent); 
    notificationManager.notify(NOTIFICATION_ID, builder.build()); 
} 

回答

1

尝试这个 builder.setAutoCancel(true);

-1

您可以通过使用

Notification.FLAG_AUTO_CANCEL 

然后开始页面的意图你想

0

如果您的通知设置要做到这一点自动取消一旦用户选择了它,它也将被删除。

OR

您也可以拨打取消()为特定的通知ID取消通知。

notificationManager.cancel(notifyId); 

MessageConversationActivity类中使用onCreate方法。

0

使用notificationManager.cancel(NOTIFICATION_ID); 它从通知管理器取消通知ID