• notification控件 通知栏


    Notification,是一种具有全局效果的通知,可以在系统的通知栏中显示。当 APP 向系统发出通知时,它将先以图标的形式显示在通知栏中。用户可以下拉通知栏查看通知的详细信息。通知栏和抽屉式通知栏均是由系统控制,用户可以随时查看。

    Notificaiton -- service -- BroadcastReceiver -- Intent(flag、Action等属性应用) -- PendingIntent

    • NotificationManager : 是状态栏通知的管理类,负责发通知、清除通知等操作。

    • Notification为通知信息类

    Notification.Builer : 使用建造者模式构建 Notification 对象。

    Notification : 通知对应类,保存通知相关的数据。

    NotificationManager 向系统发送通知时会用到。

    NotificationManager : NotificationManager 是通知管理类,它是一个系统服务。调用 NotificationManager 的 notify() 方法可以向系统发送通知。

    notification = new NotificationCompat.Builder(this,"leo")
            .setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI) //
            .setTicker("有新消息呢")    //设置状态栏的标题
            .setContentTitle("官方通知")//设置标题
            .setContentText("世界那么大,想去走走")//设置文本内容
            .setSmallIcon(R.drawable.baseline_1k_24)//设置小图标
            .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.baseline_1                      6mp_24))//设置通知大图标
            .setColor(Color.parseColor("#ff0000"))//设置小图标颜色
            .setDefaults(Notification.DEFAULT_ALL)      //设置默认的提示音
            .setPriority(Notification.PRIORITY_DEFAULT)      //设置该通知的优先级
            .setOngoing(false)              //让通知左右滑的时候不能取消通知
            .setContentIntent(pendingIntent)//设置点击通知后的跳转意图
            .setAutoCancel(true)//设置点击后自动清除通知
            .setWhen(System.currentTimeMillis())//设置通知被创建的时间,、
                            默认为系统发出通知的 时 间,通常不用设置
            .build();

    PendingIntent和Intent略有不同,它可以设置执行次数,主要用于远程服务通信、闹铃、通知、启动器、短信中,在一般情况下用的比较少。

    PendingIntent 是 Android 系统管理并持有的用于描述和获取原始数据的对象的标志(引用)。也就是说,即便创建该PendingIntent对象的进程被杀死了,这个PendingItent对象在其他进程中还是可用的。日常使用中的短信、闹钟等都用到了 PendingIntent。

    PendingIntent的位标识符:
    FLAG_CANCEL_CURRENT:如果当前系统中已经存在一个相同的 PendingIntent 对象,那么就将先将已有的 PendingIntent 取消,然后重新生成一个 PendingIntent 对象。
    FLAG_NO_CREATE:如果当前系统中不存在相同的 PendingIntent 对象,系统将不会创建该 PendingIntent 对象而是直接返回 null 。
    FLAG_ONE_SHOT:该 PendingIntent 只作用一次。
    FLAG_UPDATE_CURRENT:如果系统中已存在该 PendingIntent 对象,那么系统将保留该 PendingIntent 对象,但是会使用新的 Intent 来更新之前 PendingIntent 中的 Intent 对象数据,例如更新 Intent 中的 Extras 。

    //获取一个用于启动 Activity 的 PendingIntent 对象public static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags);
    //获取一个用于启动 Service 的 PendingIntent 对象public static PendingIntent getService(Context context, int requestCode, Intent intent, int flags);
    //获取一个用于向 BroadcastReceiver 广播的 PendingIntent 对象public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, int flags)

  • 相关阅读:
    Java项目:基于JSP的养老院管理系统
    计算机视觉 | 交通信号灯状态的检测和识别
    函数的凹凸性与拐点
    24深圳杯数学建模挑战赛A题6页初步思路+参考论文+保姆级答疑!!!
    机器学习(四十三):MLflow机器学习模型生命周期管理
    “10X 程序员是如何思考的” 阅读总结
    echarts让设置legend宽度不生效
    园子开店记:被智能的淘宝处罚,说是“预防性的违规”
    Vue3组件库打包指南,一次生成esm、esm-bundle、commonjs、umd四种格式
    Feign
  • 原文地址:https://blog.csdn.net/m0_65238452/article/details/132624558