2012-05-25 43 views
0

我已经做了一个NotificationView类来显示通知接收短信的工作正常,但当我点击通知它不会清理和通知图标仍然在通知栏上但我希望清除它pl指定提前或索里我一些提示或示例代码为感谢如果查询是得不到cleared..I标记代码关于短信接收的显示通知

感谢

上的onReceive的displayNotification方法。广播接收器

私人无效displayNotification(弦乐味精){

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); 
} 

这是NotificationView类的代码。

公共无效的onCreate(捆绑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)); 
     } 
    } 
}; 

回答

0

为什么您使用的管道( “|”)在下面的代码

notif.flags |= Notification.FLAG_AUTO_CANCEL; 

中取出,并检查

notif.flags = Notification.FLAG_AUTO_CANCEL; 
+0

感谢先生,现在它工作正常,谢谢 –

+0

先生我想申请默认通知,你从设备选择先生请告诉我如何C一组默认设置,如Show_Light,Vibrate和Sound来通知 –