Notification的基本用法

来源:互联网 发布:酥油饼网络剧 编辑:程序博客网 时间:2024/05/29 04:08
android4.0以前:
private static final int NOTIFY_ID = 0;notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);private void showNotification(Store store) {Notification notification = new Notification();notification.flags |= Notification.FLAG_SHOW_LIGHTS;notification.flags |= Notification.FLAG_AUTO_CANCEL;notification.defaults = Notification.DEFAULT_ALL;notification.icon = R.drawable.ic_launch;notification.when = System.currentTimeMillis();Intent intent = new Intent(this,AlarmActivity.class);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("store", store);PendingIntent contentIntent = PendingIntent.getActivity(this, 0,intent, PendingIntent.FLAG_UPDATE_CURRENT);//FLAG_ONE_SHOT //Change the name of the notification herenotification.setLatestEventInfo(this, store.getStoreName()+"("+store.getDistance()+")", store.getAddress(), contentIntent);notificationManager.notify(NOTIFY_ID, notification);}


android4.0以后:
private static final int NOTIFY_ID = 0;notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);private void showNotification(Store store) {Intent intent = new Intent(this,AlarmActivity.class);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("store", store);PendingIntent contentIntent = PendingIntent.getActivity(this, 0,intent, PendingIntent.FLAG_UPDATE_CURRENT);//FLAG_ONE_SHOTNotification notification = new Notification.Builder(context)         .setContentTitle(store.getStoreName()+"("+store.getDistance()+")").setContentText(store.getAddress()).setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launch) .setAutoCancel(true).setWhen(System.currentTimeMillis()).setDefaults(Notification.DEFAULT_ALL).getNotification();notificationManager.notify(NOTIFY_ID, notification);//stopSelf();}


坑爹的Google API上用法是这样的:
Notification noti = new Notification.Builder(mContext)
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.build();

我找了半天也没找到build()方法!!!

android Notification 的使用
http://www.cnblogs.com/newcj/archive/2011/03/14/1983782.html
0 0
原创粉丝点击