我的MainActivity中的代码如下:
public void onClick(View v) {
switch (v.getId()) {
case R.id.send_notice:
NotificationManager manager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification=new Notification(R.drawable.ic_launcher, "This is ticker text", System.currentTimeMillis());
notification.ledARGB=Color.RED;
notification.ledOnMS=300;
notification.ledOffMS=1000;
notification.flags |=Notification.FLAG_SHOW_LIGHTS;
Intent sendIntent =new Intent(MainActivity.this,NotificationActivity.class);
PendingIntent pendingIntent=PendingIntent.getActivity(MainActivity.this, 0, sendIntent, PendingIntent.FLAG_CANCEL_CURRENT);
//将第四个参数使用PendingIntent
notification.setLatestEventInfo(MainActivity.this, "This is Content title", "This is Content text", pendingIntent);
manager.notify(1, notification);
break;
default:
break;
}
}