Android-Notification(通知)

Android安卓状态栏消息推送通知(Notification) 我从不猜测,猜测是一个很坏的习惯——会影响正常的逻辑推理能力。              ——阿瑟·柯南·道尔 《福尔摩斯探案集》 近日,在做安卓项目开发的时候涉及到状态栏通知的需求,查了资料,总结一个简单有效的方法,下面放上代码(Kotlin版): //该代码为Kotlin,读者可根据需求稍作调整 val notificationManager = getSystemServi... 阅读详情

Notification(通知)

Notification 概述
是一种具有全局效果的通知,可以在系统的通知栏中显示,首先会表示为一个图标的形式,当用户向下滑动的时候,展示出通知具体的内容

Notification 的基本操作
Notification 的基本操作主要有创建、更新、取消这三种。一个 Notification 的必要属性有三项,如果不设置则在运行时会抛出异常:

小图标,通过 setSmallIcon() 方法设置
标题,通过 setContentTitle() 方法设置
内容,通过 setContentText() 方法设置

创建 Notification
Notification : 通知对应类,保存通知相关的数据。
NotificationManager : NotificationManager 是通知管理类,它是一个系统服务。调用 NotificationManager 的 notify() 方法可以向系统发送通知。

获取 NotificationManager 对象:
NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

代码:
private void sendNotification() {
//获取NotificationManager实例
NotificationManager notifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//实例化NotificationCompat.Builde并设置相关属性
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
//设置小图标
.setSmallIcon(R.mipmap.icon_fab_repair)
//设置通知标题
.setContentTitle(“最简单的Notification”)
//设置通知内容
.setContentText(“只有小图标、标题、内容”)
//设置通知时间,默认为系统发出通知的时间,通常不用设置
//.setWhen(System.currentTimeMillis());
//通过builder.build()方法生成Notification对象,并发送通知,id=1
notifyManager.notify(1, builder.build());
}

给 Notification 设置 Action
otification 跳转到 MainActivity 的效果,代码如下:
/**

  • 发送一个点击跳转到MainActivity的消息
    */
    private void sendSimplestNotificationWithAction() {
    //获取PendingIntent
    Intent mainIntent = new Intent(this, MainActivity.class);
    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    //创建 Notification.Builder 对象
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.mipmap.ic_launcher)
    //点击通知后自动清除
    .setAutoCancel(true)
    .setContentTitle(“我是带Action的Notification”)
    .setContentText(“点我会打开MainActivity”)
    .setContentIntent(mainPendingIntent);
    //发送通知
    mNotifyManager.notify(3, builder.build());
    }

发送具有 Action 的通知多了创建 Intent 、 PendingIntent 和 setContentIntent()

PendingIntent 是一种特殊的 Intent ,字面意思可以解释为延迟的 Intent ,用于在某个事件结束后执行特定的 Action

PendingIntent 主要可以通过以下三种方式获取:
//获取一个用于启动 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)

PendingIntent 具有以下几种 flag:
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

取消 Notification
取消通知有如下 5 种方式:
点击通知栏的清除按钮,会清除所有可清除的通知
设置了 setAutoCancel() 或 FLAG_AUTO_CANCEL 的通知,点击该通知时会清除它
通过 NotificationManager 调用 cancel(int id) 方法清除指定 ID 的通知
通过 NotificationManager 调用 cancel(String tag, int id) 方法清除指定 TAG 和 ID 的通知
通过 NotificationManager 调用 cancelAll() 方法清除所有该应用之前发送的通知

Notification 的基本操作代码
/**

  • 为了方便,大部分通知都没设置对应的Action,即PendingIntent

  • 除了sendFlagAutoCancelNotification()方法
    */
    public class SimpleNotificationActivity extends Activity implements View.OnClickListener {

    //Notification.FLAG_FOREGROUND_SERVICE //表示正在运行的服务
    public static final String NOTIFICATION_TAG = “littlejie”;
    public static final int DEFAULT_NOTIFICATION_ID = 1;

    private NotificationManager mNotificationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_simple_notification);

     findViewById(R.id.btn_remove_all_notification).setOnClickListener(this);
     findViewById(R.id.btn_send_notification).setOnClickListener(this);
     findViewById(R.id.btn_remove_notification).setOnClickListener(this);
     findViewById(R.id.btn_send_notification_with_tag).setOnClickListener(this);
     findViewById(R.id.btn_remove_notification_with_tag).setOnClickListener(this);
     findViewById(R.id.btn_send_ten_notification).setOnClickListener(this);
     findViewById(R.id.btn_send_flag_no_clear_notification).setOnClickListener(this);
     findViewById(R.id.btn_send_flag_ongoing_event_notification).setOnClickListener(this);
     findViewById(R.id.btn_send_flag_auto_cancecl_notification).setOnClickListener(this);
    
     mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    

    }

    @Override
    public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btn_remove_all_notification:
    //移除当前 Context 下所有 Notification,包括 FLAG_NO_CLEAR 和 FLAG_ONGOING_EVENT
    mNotificationManager.cancelAll();
    break;
    case R.id.btn_send_notification:
    //发送一个 Notification,此处 ID = 1
    sendNotification();
    break;
    case R.id.btn_remove_notification:
    //移除 ID = 1 的 Notification,注意:该方法只针对当前 Context。
    mNotificationManager.cancel(DEFAULT_NOTIFICATION_ID);
    break;
    case R.id.btn_send_notification_with_tag:
    //发送一个 ID = 1 并且 TAG = littlejie 的 Notification
    //注意:此处发送的通知与 sendNotification() 发送的通知并不冲突
    //因为此处的 Notification 带有 TAG
    sendNotificationWithTag();
    break;
    case R.id.btn_remove_notification_with_tag:
    //移除一个 ID = 1 并且 TAG = littlejie 的 Notification
    //注意:此处移除的通知与 NotificationManager.cancel(int id) 移除通知并不冲突
    //因为此处的 Notification 带有 TAG
    mNotificationManager.cancel(NOTIFICATION_TAG, DEFAULT_NOTIFICATION_ID);
    break;
    case R.id.btn_send_ten_notification:
    //连续发十条 Notification
    sendTenNotifications();
    break;
    case R.id.btn_send_flag_no_clear_notification:
    //发送 ID = 1, flag = FLAG_NO_CLEAR 的 Notification
    //下面两个 Notification 的 ID 都为 1,会发现 ID 相等的 Notification 会被最新的替换掉
    sendFlagNoClearNotification();
    break;
    case R.id.btn_send_flag_auto_cancecl_notification:
    sendFlagOngoingEventNotification();
    break;
    case R.id.btn_send_flag_ongoing_event_notification:
    sendFlagAutoCancelNotification();
    break;
    }
    }

    /**

    • 发送最简单的通知,该通知的ID = 1
      */
      private void sendNotification() {
      //这里使用 NotificationCompat 而不是 Notification ,因为 Notification 需要 API 16 才能使用
      //NotificationCompat 存在于 V4 Support Library
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
      .setSmallIcon(R.mipmap.ic_launcher)
      .setContentTitle(“Send Notification”)
      .setContentText(“Hi,My id is 1”);
      mNotificationManager.notify(DEFAULT_NOTIFICATION_ID, builder.build());
      }

    /**

    • 使用notify(String tag, int id, Notification notification)方法发送通知
    • 移除对应通知需使用 cancel(String tag, int id)
      */
      private void sendNotificationWithTag() {
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
      .setSmallIcon(R.mipmap.ic_launcher)
      .setContentTitle(“Send Notification With Tag”)
      .setContentText("Hi,My id is 1,tag is " + NOTIFICATION_TAG);
      mNotificationManager.notify(NOTIFICATION_TAG, DEFAULT_NOTIFICATION_ID, builder.build());
      }

    /**

    • 循环发送十个通知
      */
      private void sendTenNotifications() {
      for (int i = 0; i < 10; i++) {
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
      .setSmallIcon(R.mipmap.ic_launcher)
      .setContentTitle(“Send Notification Batch”)
      .setContentText("Hi,My id is " + i);
      mNotificationManager.notify(i, builder.build());
      }
      }

    /**

    • 设置FLAG_NO_CLEAR
    • 该 flag 表示该通知不能被状态栏的清除按钮给清除掉,也不能被手动清除,但能通过 cancel() 方法清除
    • Notification.flags属性可以通过 |= 运算叠加效果
      */
      private void sendFlagNoClearNotification() {
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
      .setSmallIcon(R.mipmap.ic_launcher)
      .setContentTitle(“Send Notification Use FLAG_NO_CLEAR”)
      .setContentText(“Hi,My id is 1,i can’t be clear.”);
      Notification notification = builder.build();
      //设置 Notification 的 flags = FLAG_NO_CLEAR
      //FLAG_NO_CLEAR 表示该通知不能被状态栏的清除按钮给清除掉,也不能被手动清除,但能通过 cancel() 方法清除
      //flags 可以通过 |= 运算叠加效果
      notification.flags |= Notification.FLAG_NO_CLEAR;
      mNotificationManager.notify(DEFAULT_NOTIFICATION_ID, notification);
      }

    /**

    • 设置FLAG_AUTO_CANCEL
    • 该 flag 表示用户单击通知后自动消失
      */
      private void sendFlagAutoCancelNotification() {
      //设置一个Intent,不然点击通知不会自动消失
      Intent resultIntent = new Intent(this, MainActivity.class);
      PendingIntent resultPendingIntent = PendingIntent.getActivity(
      this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
      .setSmallIcon(R.mipmap.ic_launcher)
      .setContentTitle(“Send Notification Use FLAG_AUTO_CLEAR”)
      .setContentText(“Hi,My id is 1,i can be clear.”)
      .setContentIntent(resultPendingIntent);
      Notification notification = builder.build();
      //设置 Notification 的 flags = FLAG_NO_CLEAR
      //FLAG_AUTO_CANCEL 表示该通知能被状态栏的清除按钮给清除掉
      //等价于 builder.setAutoCancel(true);
      notification.flags |= Notification.FLAG_AUTO_CANCEL;
      mNotificationManager.notify(DEFAULT_NOTIFICATION_ID, notification);
      }

    /**

    • 设置FLAG_ONGOING_EVENT
    • 该 flag 表示发起正在运行事件(活动中)
      */
      private void sendFlagOngoingEventNotification() {
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
      .setSmallIcon(R.mipmap.ic_launcher)
      .setContentTitle(“Send Notification Use FLAG_ONGOING_EVENT”)
      .setContentText(“Hi,My id is 1,i can’t be clear.”);
      Notification notification = builder.build();
      //设置 Notification 的 flags = FLAG_NO_CLEAR
      //FLAG_ONGOING_EVENT 表示该通知通知放置在正在运行,不能被手动清除,但能通过 cancel() 方法清除
      //等价于 builder.setOngoing(true);
      notification.flags |= Notification.FLAG_ONGOING_EVENT;
      mNotificationManager.notify(DEFAULT_NOTIFICATION_ID, notification);
      }
      }

Notification 通知效果的设置方式及注意事项,代码如下:
/**

  • 最普通的通知效果
    */
    private void showNotifyOnlyText() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setLargeIcon(mLargeIcon)
    .setContentTitle(“我是只有文字效果的通知”)
    .setContentText(“我没有铃声、震动、呼吸灯,但我就是一个通知”);
    mManager.notify(1, builder.build());
    }

/**

  • 展示有自定义铃声效果的通知
  • 补充:使用系统自带的铃声效果:Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, “6”);
    */
    private void showNotifyWithRing() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(“我是伴有铃声效果的通知”)
    .setContentText(“美妙么?安静听~”)
    //调用系统默认响铃,设置此属性后setSound()会无效
    //.setDefaults(Notification.DEFAULT_SOUND)
    //调用系统多媒体裤内的铃声
    //.setSound(Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,“2”));
    //调用自己提供的铃声,位于 /res/values/raw 目录下
    .setSound(Uri.parse(“android.resource://com.littlejie.notification/” + R.raw.sound));
    //另一种设置铃声的方法
    //Notification notify = builder.build();
    //调用系统默认铃声
    //notify.defaults = Notification.DEFAULT_SOUND;
    //调用自己提供的铃声
    //notify.sound = Uri.parse(“android.resource://com.littlejie.notification/”+R.raw.sound);
    //调用系统自带的铃声
    //notify.sound = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,“2”);
    //mManager.notify(2,notify);
    mManager.notify(2, builder.build());
    }

/**

  • 展示有震动效果的通知,需要在AndroidManifest.xml中申请震动权限
  • 补充:测试震动的时候,手机的模式一定要调成铃声+震动模式,否则你是感受不到震动的
    */
    private void showNotifyWithVibrate() {
    //震动也有两种设置方法,与设置铃声一样,在此不再赘述
    long[] vibrate = new long[]{0, 500, 1000, 1500};
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(“我是伴有震动效果的通知”)
    .setContentText(“颤抖吧,凡人~”)
    //使用系统默认的震动参数,会与自定义的冲突
    //.setDefaults(Notification.DEFAULT_VIBRATE)
    //自定义震动效果
    .setVibrate(vibrate);
    //另一种设置震动的方法
    //Notification notify = builder.build();
    //调用系统默认震动
    //notify.defaults = Notification.DEFAULT_VIBRATE;
    //调用自己设置的震动
    //notify.vibrate = vibrate;
    //mManager.notify(3,notify);
    mManager.notify(3, builder.build());
    }

/**

  • 显示带有呼吸灯效果的通知,但是不知道为什么,自己这里测试没成功
    */
    private void showNotifyWithLights() {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(“我是带有呼吸灯效果的通知”)
    .setContentText(“一闪一闪亮晶晶~”)
    //ledARGB 表示灯光颜色、 ledOnMS 亮持续时间、ledOffMS 暗的时间
    .setLights(0xFF0000, 3000, 3000);
    Notification notify = builder.build();
    //只有在设置了标志符Flags为Notification.FLAG_SHOW_LIGHTS的时候,才支持呼吸灯提醒。
    notify.flags = Notification.FLAG_SHOW_LIGHTS;
    //设置lights参数的另一种方式
    //notify.ledARGB = 0xFF0000;
    //notify.ledOnMS = 500;
    //notify.ledOffMS = 5000;
    //使用handler延迟发送通知,因为连接usb时,呼吸灯一直会亮着
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
    @Override
    public void run() {
    mManager.notify(4, builder.build());
    }
    }, 10000);
    }

/**

  • 显示带有默认铃声、震动、呼吸灯效果的通知
  • 如需实现自定义效果,请参考前面三个例子
    */
    private void showNotifyWithMixed() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(“我是有铃声+震动+呼吸灯效果的通知”)
    .setContentText(“我是最棒的~”)
    //等价于setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
    .setDefaults(Notification.DEFAULT_ALL);
    mManager.notify(5, builder.build());
    }

/**

  • 通知无限循环,直到用户取消或者打开通知栏(其实触摸就可以了),效果与FLAG_ONLY_ALERT_ONCE相反
  • 注:这里没有给Notification设置PendingIntent,也就是说该通知无法响应,所以只能手动取消
    */
    private void showInsistentNotify() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(“我是一个死循环,除非你取消或者响应”)
    .setContentText(“啦啦啦~”)
    .setDefaults(Notification.DEFAULT_ALL);
    Notification notify = builder.build();
    notify.flags |= Notification.FLAG_INSISTENT;
    mManager.notify(6, notify);
    }

/**

  • 通知只执行一次,与默认的效果一样
    */
    private void showAlertOnceNotify() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(“仔细看,我就执行一遍”)
    .setContentText(“好了,已经一遍了~”)
    .setDefaults(Notification.DEFAULT_ALL);
    Notification notify = builder.build();
    notify.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
    mManager.notify(7, notify);
    }

/**

  • 清除所有通知
    */
    private void clearNotify() {
    mManager.cancelAll();
    }
Android studio 28 通知栏报错Failed to post notification on channel "null" 今天老师上课上到通知,教材是第一行代码,可能教材上的源码太久了,我在用安卓9的时候,模拟器报错Failed to post notification on channel “null”,在网上查了很久才知道,Notification在android 26以上设置时,需要设置渠道信息才可以正常显示通知,这是 官方文档地址[https://developer.android.google.cn/abo... 阅读详情

相关推荐

实现Android常驻通知栏Notification的完整指南

Android Notification是Android系统中用于向用户显示应用状态更新的一种机制。它能够让应用在不打断用户当前操作的情况下,展示信息。随着Android版本的更新,Notification的管理和用户交互方式也发生了很大的变化。创建一个Notification Channel,首先需要定义一个Channel ID和Channel Name。Channel ID是一个字符串,用于在程序中唯一标识这个Channel。Channel Name是用户可见的名称,应简洁明了地描述通知的用途。

weixin_36073714的博客 1634

【Android】状态栏通知Notification、NotificationManager详解

在Android系统中,发一个状态栏通知还是很方便的。下面我们就来看一下,怎么发送状态栏通知,状态栏通知又有哪些参数可以设置?首先,发送一个状态栏通知必须用到两个类:  NotificationManager 、 Notification。NotificationManager :  是状态栏通知的管理类,负责发通知、清楚通知等。NotificationManager 是一个系统Service,必须通过 getSystemService()方法来获取。NotificationManager nm = (No

幻影浪子 11万+

HFSS微带线仿真从零到一:材料参数与求解设置优化指南

在射频电路设计中,微带线仿真涉及电磁场求解与传输线理论,其精度高度依赖材料参数和求解设置。相对介电常数、损耗角正切和导体电导率等参数直接影响特性阻抗与插入损耗,而求解频率、网格划分和参数扫描则决定仿真效率与收敛性。合理设置这些参数可显著提升S参数准确性,避免设计迭代。应用场景包括天线馈线、滤波器和微波互连。本文基于HFSS微带线仿真实践,系统讲解材料选择与参数优化全链路,帮助工程师快速复现可靠模型。

weixin_29192211的博客 80

Android Notification通知的使用

Notification : 通知 一 使用大纲 1 获取通知栏管理 NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 2 实例化通知栏构造器 Notification notification = new NotificationCompat.Builder() .setContentTitle() ...

m0_45877477的博客 739

画了多年板子才搞懂:Allegro内电层负片连接,Thermal Relief和Anti-Pad避坑全解析

本文深入解析Allegro内电层设计中Thermal Relief与Anti-Pad的关键技术要点,帮助工程师避免常见设计陷阱。通过六层板实战案例,详细阐述负片连接逻辑、热风焊盘参数设计及隔离盘优化策略,提升PCB设计的可靠性与EMI性能。

weixin_28731223的博客 265

HFSS初学笔记(二)——75Ω带状线设计

本文利用HFSS软件设计并优化了一条75Ω的带状线结构,通过调整几何参数和介质材料,实现了精确的阻抗控制。仿真结果显示,该带状线在高频信号传输中的表现优越,具有良好的S参数、低插入损耗和极小的信号反射损耗。

2401_87464239的博客 4547

通知栏notification管理工具类【直接可用】

创建通知栏,适配8.0系统 final String CHANNEL_ID = "channel_id"; //通道渠道id final String CHANEL_NAME = "吉智警务通"; //通道渠道名称 NotificationChannel channel = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES...

fengyeNom1的博客 1549

全局特征描述子 CVFH (Clustered Viewpoint Feature Histogram) 原理

特性VFHCVFH处理对象整个物体点云物体点云被分割后的稳定表面块(簇)对遮挡的鲁棒性弱。遮挡会破坏全局形状,导致描述子失效。极强。只依赖于稳定存在的部分。描述子维度263 维308 维 (263 + 45 SC)输出数量一个物体产生1 个描述子一个物体可能产生多个签名计算复杂度相对较低较高(需先聚类)主要应用场景完整、分割良好的物体存在遮挡、背景杂波的不完整物体。

weixin_37079656的博客 620

Notification使用以及PendingIntent.getActivity()

public void sendNotification(Context ctx,String message) { //get the notification manager String ns = Context.NOTIFICAT...

weixin_30555125的博客 248

❤️爆肝十二万字《python从零到精通教程》,从零教你变大佬❤️(建议收藏)

文章目录强烈推荐系列教程,建议学起来!!一.pycharm下载安装二.python下载安装三.pycharm上配置python四.配置镜像源让你下载嗖嗖的快4.1pycharm内部配置4.2手动添加镜像源4.3永久配置镜像源五.插件安装(比如汉化?)5.1自动补码神器第一款5.2汉化pycharm5.3其它插件六.美女背景七.自定义脚本开头八、这个前言一定要看九、python入门十、python缩进十一、Python注释1.单行注释2.多行注释十二、Python 变量1.变量定义理解2. 变量名命名3. 分

全栈川川 26万+

塔石DTU通过MQTT传递数据教程

塔石通过MQTT通讯上传ADL400电表用电量。

renkai721的专栏 254

Android 12.0 中 清除通知 , 系统源码分析(二)

(2) 源码路径: frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java。特别提示:notificationManager.cancelAll() 是删除由该APP发出的所有通知,即 "App的包名"对应下的所有通知.(1)源码路径: frameworks/base/core/java/android/app/NotificationManager.java。

Smile_729day的博客 1175

【Go语言实战】(3) Gin + Gorm 简单备忘录 | 含接口文档

Go语言实战:TodoList 备忘录

面向生活编程 6140

安卓开发 通知栏Notification详解

安卓开发通知栏Notification的详细介绍和用法示例

wm 6942

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

安卓Notification通知栏全解

全栈工程师开发手册 (作者:栾鹏) 安卓教程全解 安卓通知栏是提醒用户信息有效手段,也是通过用户的行为触发事件服务的方式。 Notification允许在当前应用程序不活动或不可见时向用户发送信号。 创建通知栏有使用Notification直接创建何使用Notification.Builder创建两种方法 1、使用Notification直接创建通知栏 private

1866

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Android通知栏-Notification(通知消息)

1.概述 当应用程序在后台运行,希望向用户发出一些提示学习,就需要借助Notification(通知)来实现。在发出一条通知后,手机最上方的状态栏会显示一个通知的图标,下拉状态栏后就可以看到通知的详细内容。 1.1 视图分类 Notification有两种视觉风格,一种是标准视图(Normal View),另外一种是大视图(Big view)。标准视图在Android中各...

云上道人的博客 4万+

通知栏如何更新android,安卓状态栏通知Notification方法更新(setLatestEventInfo)

今天使用安卓状态栏通知的时候,发现Notification的setLatestEventInfo构造方法画上的横线,也就是以前版本的方法,将要舍弃,强迫症没办法啊,于是查询资料找到了最新的构造方法,留存下吧。Notification notification = new Notification.Builder(context).setContentTitle("标题")//设置通知标题.setC...

weixin_35131425的博客 1328

android实现通知,Android中的3种通知Notification

Android中的Notification分为三种:1、普通Notification2、折叠Notification3、悬浮Notification1、普通Notification//普通通知val mIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://blog.csdn.net/qq_40716430/article/details/10...

weixin_42347869的博客 833

Android发送通知——通知栏(Notification)

通知是指 Android 在您应用的界面之外显示的消息,旨在向用户提供提醒、来自他人的通信信息或您应用中的其他实时信息。在发出一条通知后,手机最上方的状态栏会显示一个通知的图标,下拉状态栏后就可以看到通知的详细内容。用户可以点按通知来打开应用,或直接从通知中执行操作。

weixin_43977664的博客 1万+

Android-Notification安卓手机通知栏通知的开发

一、概述           Notification是显示在手机状态栏的消息(手机状态栏位于手机最顶端),代表一种全局效果的通知。 二、通知栏的内容        图标、标题、内容、时间、点击后响应 三、实现通知栏      (1)获取NotificationManager。      (2)显示通知栏:notify(id, notification);      (3)取消通知栏

雨泪不轻扬 1577

安卓中Notification通知的详解

这是关于androidNotification的详解,希望可以帮助到大家

知他人之所知,晓他人之不晓。 2216

Android的notification通知

概括: Android使用notification实现消息提醒,提供通知栏和通知抽屉查看通知和通知详情,Android的notification机制应用非常广泛,是指在应用程序之外显示的消息,布局由系统模板决定,开发者只需要定义模板中各部分的内容,通知详情就会在点开后展开视图显示设置的内容。 目前大体分为状态栏图标通知、悬挂提醒式通知、锁屏通知及圆点通知,从Android8.0开始必须为所有通知分配一个或多个通道,否则通知将不会显示。Android8.0及以上通过通道的importance属性设置重要性

weixin_51872136的博客 3638

安卓中通知(Notification)的基本使用方法

安卓中通知(Notification)的基本使用方法 1. 通知的使用场合  当某个应用程序希望向用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助通知来实现。发出一条通知后,手机最上方的状态栏中会显示一个通知的图标,下拉状态栏后可以看到通知的详细内容。  2. 通知的创建步骤    (1)获取NotificationManager实例,可以通过调用Co

dotedy的博客 595

android之Notification通知

<br />我们在用手机的时候,如果来了短信,而我们没有点击查看的话,是不是在手机的最上边的状态栏里有一个短信的小图标提示啊?你是不是也想实现这种功能呢?今天的Notification就是解决这个问题的。<br />package cn.com.chenzheng_java; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import an

梦中一夜下江南 5万+

安卓开发--通知Notification

先在AndroidManifest.xml里面添加权限。必须提供,显示在状态栏(纯白色,推荐使用矢量图)VISIBILITY_SECRET:完全不显示。Android 8.0+ 必须为通知分配渠道。VISIBILITY_PUBLIC:完全显示。可选,展开后显示(通常用于联系人头像)小图标 (Small Icon)大图标 (Large Icon)决定通知的显示位置和干扰程度。渠道 (Channel)构建兼容不同版本的通知。13.通知的可见性控制。状态栏显示+默认声音。

m0_50891221的博客 402
上一篇: Android-StateListDrawable(状态选择器)
下一篇: Android-主题和样式
Android_xi
博客等级 码龄8年 4粉丝 59原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值