首页 > 其他 > 详细

notification新旧用法

时间:2015-10-08 16:09:09      阅读:180      评论:0      收藏:0      [点我收藏+]
api10版本以前 
protected void showNotification() { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Notification notification = new Notification(this,R.drawable.ic_launcher); Notification notification = new Notification(R.drawable.ic_launcher,"",System.currentTimeMillis() ); PendingIntent contentIndent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this,MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(MainActivity.this, "通知内容", "通知", contentIndent); notificationManager.notify(id,notification); }
api10以后
protected void showNotification() {  
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  
        Builder builder = new Notification.Builder(MainActivity.this);  
        PendingIntent contentIndent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this,MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);  
        builder . setContentIntent(contentIndent) .setSmallIcon(R.drawable.ic_launcher)//设置状态栏里面的图标(小图标)                    
 .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.i5))//下拉下拉列表里面的图标(大图标)      
  .setTicker("通知!") //设置状态栏的显示的信息 .setWhen(System.currentTimeMillis())//设置时间发生时间 .setAutoCancel(true)//设置可以清除 .setContentTitle("title")//设置下拉列表里的标题 .setContentText("contenttext");//设置上下文内容 Notification notification = builder.getNotification(); notificationManager.notify(id,notification); }

notification新旧用法

原文:http://www.cnblogs.com/xiaoliboke/p/4861017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!