状态栏发送通知

来源:互联网 发布:js字符串转义函数 编辑:程序博客网 时间:2024/06/05 18:16
public class SendNotification extends Activity {  private NotificationManager nm;  private Button btnSend;  private Button btnCancel;    @Override  public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);      setContentView(R.layout.main);      setupViews();  }   private void setupViews() {  btnSend = (Button) findViewById(R.id.send);  btnCancel = (Button) findViewById(R.id.cancel);  String service = Context.NOTIFICATION_SERVICE;  nm = (NotificationManager) getSystemService(service); // get system service  final Context context = SendNotification.this;  btnSend.setOnClickListener(new OnClickListener() {  public void onClick(View v) {  Notification n = new Notification();  n.icon = R.drawable.icon;  n.tickerText = "Notification";  n.when = System.currentTimeMillis();  //n.flags=Notification.FLAG_ONGOING_EVENT;  Intent intent = new Intent(context, SendNotification.class);  PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);  n.setLatestEventInfo(context, "title","content", pi);  nm.notify(1, n);  }  });      btnCancel.setOnClickListener(new OnClickListener() {    public void onClick(View v) {  nm.cancel(1);  }  });  }  }

0 0
原创粉丝点击