1. [代码]API 1
private void showNotification(Context context, String ticker,
String title, String describe, int icon, Intent intent) {
int id = mIncrement++;
NotificationManager nm = (NotificationManager)context.getSystemService(
Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Notification notification = new Notification(icon,
ticker,System.currentTimeMillis());
notification.setLatestEventInfo(context, title, describe, pendingIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(id, notification);
}
2. [代码]API 11
private void showNotificaion(Context context, int id) {
NotificationManager nm = (NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(Intent.ACTION_MAIN);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Notification notification = new Notification.Builder(context)
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("describe")
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.build();
nm.notify(id, notification);
}