显示有关短信接收的通知

时间:2012-05-25 06:43:15

标签: android eclipse java-ee

我已经制作了一个NotificationView类来显示接收SMS的通知,但是当我点击Notification时它没有清理,通知图标仍保留在通知栏上但是我希望清理它pl指定我的一些提示或示例代码,提前感谢或抱歉如果查询未被清除..我标记代码

谢谢

displayNotification OnReceive上的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);
}

这是NotificationView类的代码。

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

1 个答案:

答案 0 :(得分:0)

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

notif.flags |= Notification.FLAG_AUTO_CANCEL; 

将其删除并检查

notif.flags = Notification.FLAG_AUTO_CANCEL; 
相关问题