1.普通通知
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "普通通知", System.currentTimeMillis());Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:18874217413"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "亲爱的移动用户", "您手机至2014/2/27已欠费3元整。", contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
manager.notify(10, notification);
2.自定义通知
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.icon = R.drawable.ic_launcher;
notification.tickerText = "自定义通知";
notification.when = System.currentTimeMillis();
notification.sound = Uri.parse("android.resource://"
+ this.getPackageName() + "/" + R.raw.beep);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:18874217413"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
RemoteViews contentView = new RemoteViews(this.getPackageName(), R.layout.notification_item);
contentView.setTextViewText(R.id.tv, "亲爱的移动用户");
notification.contentView = contentView;
notification.contentIntent = contentIntent;
notification.flags = Notification.FLAG_AUTO_CANCEL;
manager.notify(20, notification);
3.Builder
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setTicker("10086提醒你,您手机至2014/2/27已欠费3元整。");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle("亲爱的移动用户");
builder.setContentText("10086提醒你,您手机至2014/2/27已欠费3元整。");
builder.setAutoCancel(true);
Intent intent2 = new Intent();
intent2.setAction(Intent.ACTION_CALL);
intent2.setData(Uri.parse("tel:18674619484"));
PendingIntent contentIntent = PendingIntent.getActivity(context,0,intent,0);
builder.setContentIntent(contentIntent);
manager.notify(10, builder.build());