zoukankan      html  css  js  c++  java
  • Android中在通知栏内常驻应用程序消息

    // 添加常驻通知
    private void setNotification() {
        NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.icon, getString(R.string.app_name), System.currentTimeMillis());
        Intent intent = new Intent(this, Sample.class);
        notification.flags = Notification.FLAG_ONGOING_EVENT; // 设置常驻 Flag
        PendingIntent contextIntent = PendingIntent.getActivity(this, 0, intent, 0);
        notification.setLatestEventInfo(getApplicationContext(), getString(R.string.app_name), getString(R.string.information), contextIntent);
        notificationManager.notify(R.string.app_name, notification);
    }
     
    // 取消通知
    private void cancelNotification() {
        NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(R.string.app_name);
    }


    说明:通过 setNotification() 可以在通知栏中添加一条常驻通知,通过 cancelNotification() 取消该通知。
  • 相关阅读:
    1282 回文数猜想
    1279 验证角谷猜想
    1205 吃糖果
    1201 18岁生日
    1106 排序
    2024 C语言合法标识符
    196 让气球飞吧
    1001 Sum Problem
    if语句
    三元运算符
  • 原文地址:https://www.cnblogs.com/l2rf/p/3009192.html
Copyright © 2011-2022 走看看