• 添加常驻Notification


      private static final int NOTIFICATION_ID=250;  //用来标示notification,通过notificatinomanager来发布同样标示的notification将更新旧的通知,同时取消notification也需要这个标示(android很多地方都用到标示这么一个玩意)
      
        private void setNotification(String note) {
         //获取系统通知服务
            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            Notification notification = new Notification();
            notification.icon = R.drawable.notify;   //通知图标,官方文档中说必须有icon才能显示出notification
            notification.when = System.currentTimeMillis();
            notification.tickerText = note;    //通知出现在标题栏时显示的内容
            notification.flags = Notification.FLAG_ONGOING_EVENT; // 设置常驻Flag
            notification.defaults = Notification.DEFAULT_SOUND;   //设置notification的提示音为系统默认提示声音
            notification.setLatestEventInfo(this, "提示消息", note, null);  
            notificationManager.notify(NOTIFICATION_ID, notification);
        }
    
        // 取消通知
        private void cancelNotification() {
            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notificationManager.cancel(NOTIFICATION_ID);
        }
     
  • 相关阅读:
    python学习笔记(excel中处理日期格式)
    python学习笔记(生成xml)
    python学习笔记(接口自动化框架 V1.0)
    python学习笔记(excel+unittest)
    刷题[RoarCTF 2019]Easy Java
    刷题[GKCTF2020]
    php bypass disable function
    刷题[MRCTF2020]Ezpop
    刷题[安恒DASCTF2020四月春季赛]Ez unserialize
    刷题[HFCTF2020]EasyLogin
  • 原文地址:https://www.cnblogs.com/mushishi/p/3394594.html
Copyright © 2020-2023  润新知