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

Notification的使用

时间:2015-07-01 20:47:17      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

创建一个类专门管理Notification,一个方法显示,一个方法取消!

public class Notification_Manager {
 Activity context;
 public Notification_Manager(Activity context) {
  this.context=context;
 }
 public  void showNotification(){
  NotificationManager  manager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  //参数:   上下文环境, 瞬时消息(一闪而过),时间
     Notification  notification=new Notification(R.drawable.ic_launcher, "固定资产", System.currentTimeMillis());
    
    
     /*
     //NOtification的高级用法: 播放音频,震动(需要写震动权限),LED灯,及默认的设置
     Uri soundUri=Uri.fromFile(new File("地址 "));
     //播放指定的音频,即发出提示声
     notification.sound=soundUri;
    
     //设置一个静止和震动的数组,索引0:静止时间,索引1:震动时间 ,依次类推
        long[]   vibrates=new long[]{0,1000,1000,1000}; 
     notification.vibrate=vibrates;
    
     //以写绿色LED灯为例:
     notification.ledARGB=Color.GREEN;  //灯的颜色
     notification.ledOffMS=1000;        //灯关闭的时间
     notification.ledOnMS=1000;         //灯亮起的时间
     notification.flags=Notification.FLAG_SHOW_LIGHTS;//指示flags的行为
     //若是嫌麻烦,那就用默认的设置:
     notification.defaults=Notification.DEFAULT_ALL;
     */
    
    
 
    
     Intent  intent=new Intent( context,context.getClass() );
     PendingIntent  contentIntent= PendingIntent.getActivity(context, 0, intent,PendingIntent.FLAG_CANCEL_CURRENT);
     notification.setLatestEventInfo(context,"固定资产", "正在运用", contentIntent);
  //参数: id ,notification对象
     manager.notify(0, notification);
 }
 
 public void cancelNotification(){
  NotificationManager  manager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
     //取消id为0的消息提示框
  manager.cancel(0);
 }
 

}

Notification的使用

标签:

原文地址:http://my.oschina.net/u/2406195/blog/473044

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