首页 > 其他 > 详细

Notification的使用

时间:2015-07-01 20:44:32      阅读:229      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!