我做了一个 通知View
类,以显示收到 SMS
通知后的通知,这些通知效果良好,但当我点击 通知
时,它不干净,通知图标留在通知栏上,但我希望清除它,但我想事先为感谢指定一些提示或样本代码,如果查询没有被清除,我很抱歉。
谢谢 谢谢
display通知
方法,在 broadcastReceiver
private void displayNotification(String msg){
Intent i = new Intent(this.context,NotificationView.class);
i.putExtra("ID", ID);
/*i.putExtra("msg",msg);*/
PendingIntent pendInt = PendingIntent.getActivity(context, 0, i, 0);
Notification notif = new Notification(R.drawable.notify,"Receiving SMS",System.currentTimeMillis());
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notif.setLatestEventInfo(context, "SMS", msg, pendInt);
notif.flags |= Notification.DEFAULT_ALL;
notif.flags |= Notification.DEFAULT_VIBRATE;
notif.flags |= Notification.DEFAULT_LIGHTS;
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notif.ledARGB = Color.WHITE;
notif.ledOnMS = 1500;
notif.ledOffMS = 1500;
nm.notify(ID, notif);
}
这是《通知观察》课的代码。
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.notificationview);
txtNotify = (TextView)findViewById(R.id.txtNotification);
ID = getIntent().getExtras().getInt("ID");
/*txtNotify.setText(getIntent().getExtras().getString("msg"));*/
}
private View.OnClickListener txtClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.txtNotification:
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
txtNotify.setText("");
nm.cancel(ID);
nm.cancelAll();
NotificationView.this.startActivity(new Intent(NotificationView.this,ZigbeeActivity.class));
}
}
};