首页 \ 问答 \ 单击后,从通知区域中删除通知(Remove Notification from Notification area once it is clicked)

单击后,从通知区域中删除通知(Remove Notification from Notification area once it is clicked)

每当收到包含特定关键字的新邮件时,我都会显示通知。 我使用以下代码在通知区域显示通知,

String contentTitle = "V-Card Received"; 
String contentText = "You have reeived a new V-Card"; 
 mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, receiveVCard.class);
 notificationIntent.putExtra("sender", sender);
notificationIntent.putExtra("vCardString", messages[i].getDisplayMessageBody());
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
int icon = R.drawable.contactvcard;
CharSequence tickerText = "V-Card Received";
long when = System.currentTimeMillis();
notifyDetails = new Notification(icon, tickerText, when);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, pendingIntent); 
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); 
notifyDetails.flags =Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

现在,我想在用户点击通知后删除该通知。 我已使用Notification.FLAG_AUTO_CANCEL取消通知。 但即使用户点击它也不会删除通知。 当用户点击通知时,是否有其他方法可以删除通知。


I am displaying a notification whenever a new message is received that contains particular keywords. I have used following code to show the notification in the notification area,

String contentTitle = "V-Card Received"; 
String contentText = "You have reeived a new V-Card"; 
 mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, receiveVCard.class);
 notificationIntent.putExtra("sender", sender);
notificationIntent.putExtra("vCardString", messages[i].getDisplayMessageBody());
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
int icon = R.drawable.contactvcard;
CharSequence tickerText = "V-Card Received";
long when = System.currentTimeMillis();
notifyDetails = new Notification(icon, tickerText, when);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, pendingIntent); 
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); 
notifyDetails.flags =Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

Now I want to remove the notification once the user clicks on it. I Have used Notification.FLAG_AUTO_CANCEL to cancel the notification. But it is not removing the notification even if the user clicks on it. Is there any other way to remove the notification, when the user clicks on the notification.


原文:https://stackoverflow.com/questions/13853696
更新时间:2024-03-31 15:03

最满意答案

请参考这个plnkr 。 我使用了与您相同的基本思想,按字母顺序创建colDefs,然后在onGridReady函数中将列移动到各自的位置。 有两个函数可以用来做这个,第二个在我看来更可取:

moveColumn(colKey, toIndex)
//colKey refers to the id of the column which defaults to the specified field
//toIndex is simply a number that is within the range of columns.

moveColumns(colKeys[], toIndex)
//colKeys[] is an array in the order that you want them to be
  displayed starting at the toIndex

以下是我在plnkr中实现它的方法:

private onReady() {

    // this.gridOptions.columnApi.moveColumn('name',1)
    // this.gridOptions.columnApi.moveColumn('country',2)
    // this.gridOptions.columnApi.moveColumn('dob',3)
    // this.gridOptions.columnApi.moveColumn('skills',4)
    // this.gridOptions.columnApi.moveColumn('proficiency',5)
    // this.gridOptions.columnApi.moveColumn('mobile',6)
    // this.gridOptions.columnApi.moveColumn('landline',7)
    // this.gridOptions.columnApi.moveColumn('address',8),

    this.gridOptions.columnApi.moveColumns(['name', 'country', 'dob', 'skills', 'proficiency', 'mobile', 'landline', 'address'],1)

}

如果您想使用它,还有一个可用的功能:

moveColumnByIndex(fromIndex, toIndex)
//This uses just indexes and not the colid/colkey idea if you prefer
  to keep it more anonymous 

Please refer to this plnkr. I used the same basic idea that you had, creating the colDefs in alphabetical order then in the onGridReady function moved the columns to their respective placements. There are two functions that are useful in doing this, the second is much preferable in my opinion:

moveColumn(colKey, toIndex)
//colKey refers to the id of the column which defaults to the specified field
//toIndex is simply a number that is within the range of columns.

moveColumns(colKeys[], toIndex)
//colKeys[] is an array in the order that you want them to be
  displayed starting at the toIndex

Here is how I implemented it in the plnkr:

private onReady() {

    // this.gridOptions.columnApi.moveColumn('name',1)
    // this.gridOptions.columnApi.moveColumn('country',2)
    // this.gridOptions.columnApi.moveColumn('dob',3)
    // this.gridOptions.columnApi.moveColumn('skills',4)
    // this.gridOptions.columnApi.moveColumn('proficiency',5)
    // this.gridOptions.columnApi.moveColumn('mobile',6)
    // this.gridOptions.columnApi.moveColumn('landline',7)
    // this.gridOptions.columnApi.moveColumn('address',8),

    this.gridOptions.columnApi.moveColumns(['name', 'country', 'dob', 'skills', 'proficiency', 'mobile', 'landline', 'address'],1)

}

There is one more function that is available to you if you would like to use it:

moveColumnByIndex(fromIndex, toIndex)
//This uses just indexes and not the colid/colkey idea if you prefer
  to keep it more anonymous 

相关问答

更多