码迷,mamicode.com
首页 > 其他好文 > 详细

Notification新旧用法

时间:2015-05-14 11:33:30      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

//api 11 版本之前:
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, "您的BMI值过高", "通知监督人", contentIndent);  
        //加i是为了显示多条Notification  
        notificationManager.notify(i,notification);  
        i++;  
    } 

 

// api 11 版本之后:
protected void showNotification2() {  
        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("this is bitch!") //设置状态栏的显示的信息  
               .setWhen(System.currentTimeMillis())//设置时间发生时间  
               .setAutoCancel(true)//设置可以清除  
               .setContentTitle("This is ContentTitle")//设置下拉列表里的标题  
               .setContentText("this is ContentText");//设置上下文内容  
        Notification notification = builder.getNotification();  
        //加i是为了显示多条Notification  
        notificationManager.notify(i,notification);  
        i++;
    }  

 

Notification新旧用法

标签:

原文地址:http://www.cnblogs.com/guojing1991/p/4502556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!