今天在Android 8.0上使用通知的时候,遇到一个问题,只要一发出通知,就弹出系统界面已停止运行的弹框。如下图所示

代码如下:

NotificationChannel chan1 = new NotificationChannel(PRIMARY_CHANNEL,"cd", NotificationManager.IMPORTANCE_DEFAULT);
chan1.setLightColor(Color.GREEN);
chan1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager.createNotificationChannel(chan1);builder = new Notification.Builder(getApplicationContext(), PRIMARY_CHANNEL).setContentTitle("ds").setContentText("fa").setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true);
notificationManager.notify(NOTI_ID, builder.build());

Log显示如下:

I/DynamiteModule: Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:19
I/DynamiteModule: Selected remote version of com.google.android.gms.maps_dynamite, version >= 19
I/Google Maps Android API: Google Play services client version: 11400000
I/Google Maps Android API: Google Play services package version: 11745036
I/zygote64: Do full code cache collection, code=124KB, data=85KB
I/zygote64: After code cache collection, code=122KB, data=70KB
I/zygote64: Do partial code cache collection, code=124KB, data=73KB
I/zygote64: After code cache collection, code=124KB, data=73KB
I/zygote64: Increasing code cache capacity to 512KB
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/Choreographer: Skipped 77 frames!  The application may be doing too much work on its main thread.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 4
W/zygote64: Verification of void j.<clinit>() took 305.110ms

刚开始根据log在google上搜了半天,没半点眉目,之后很无奈的一行一行的注释掉代码排除问题所在。结果发现

builder = new Notification.Builder(getApplicationContext(), PRIMARY_CHANNEL).setContentTitle("ds").setContentText("fa") .setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true);

把上面红色部分注释掉,正常,取消注释就崩掉,那么这就是问题所在了。把图片复制到drawable-xx文件夹下,

setSmallIcon(R.mipmap.ic_launcher)改为 setSmallIcon(R.drawable.ic_launcher)就正常了。虽然问题解决了,但是依然很困惑。drawable和
mipmap在使用上应该是一样的,只是mipmap在性能上做了优化。希望有知道的能解释一下

Android O使用通知遇到的坑相关推荐

  1. Android开发笔记——Android 9发送通知

    Android 9 发送通知 发送通知 布局文件 程序代码 运行截图 发送通知 布局文件 <?xml version="1.0" encoding="utf-8&q ...

  2. Android代码删除通知,Android:从通知中删除通知b

    Android:从通知中删除通知b 我已经创建了一个应用程序,并且我设法在android通知栏中添加通知. 现在我需要示例如何从事件通知栏中删除该通知? 11个解决方案 197 votes 你可以尝试 ...

  3. 转:android.support升级到androidx踩坑记录

    原文链接:android.support升级到androidx踩坑记录 - 简书 年前想着Google老大之前提醒过将项目升级到androidx,所以年前一通操作猛如虎把Android Studio唰 ...

  4. iphone通知和android,手机App 通知数量太多,让你备感压力吗?教你如何消除令人心烦的信息通知(iPhone、Android)...

    手机APP右上角通常会显示通知数量,那个数字或许对有些人来说是倍感压力的,想要清除他却又无法,能有消除App通知数量标记的方法吗?当然有!小编这篇就是要教大家如何在iPhone.Android手机上消 ...

  5. android显示通知图标大全,Android推送通知:图标未显示在通知中,而是显示白色方块...

    Android推送通知:图标未显示在通知中,而是显示白色方块 我的应用会生成通知,但我没有显示为该通知设置的图标.相反,我得到一个白色方块. 我已经尝试调整图标的大小(尺寸720x720,66x66, ...

  6. Android O 自定义通知实例及一个自定义自动适配缩放图片至特定大小的田字格ImageView

    这一篇博文的思路很简单,没有什么深入的理论,源由是最近在实习公司里开发用到了Android O的通知,发现与以往有所不同,相关的资料是有,但是大部分都不适用于这个版本,这里只是写一个非常简单的Demo ...

  7. android锁定屏幕通知_如何在Android锁定屏幕上隐藏敏感通知

    android锁定屏幕通知 When Google brought notifications to Android's lock screen, it was a game changer. Ins ...

  8. Android Q中通知的设置

    Android Q中通知的设置项 AndroidQ中,进入系统设置–通知中心,可以对通知的显示进行设置.其中常用的两个: (1)锁定屏幕上的通知 对应的字段: Settings.Secure.LOCK ...

  9. Android上架应用宝的那些坑

    Android上架应用宝的那些坑 前言 都遇到了哪些问题 应用简介敏感词 应用截图(宣传图)敏感词 需提供软著版权证明 隐私权限 安全评估 账号问题 前言 在多年的Android生涯中,前两年的APP ...

最新文章

  1. 爬虫之requests模块cookieJar对象转换为cookies字典的方法
  2. 在symfony2项目中100%提升doctrine的性能
  3. RSTP的根保护功能
  4. 数据库开发基本操作-数据库基础知识
  5. pandas 排序一个变量
  6. 经典C语言程序100例之二九
  7. C++ STL 一般总结
  8. markov chain, MRP MDP
  9. input子系统基础之按键2——input设备应用层编程实践
  10. python 字符串去重且相同字符最多出现2次_【Python】获取字符串中出现次数最多/少的字符...
  11. HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)
  12. php获取2次跳转之后的网址,爬虫:获取多次跳转后的页面url
  13. 数值分析共轭梯度法matlab程序,数值分析11(共轭梯度法).ppt
  14. SQL Server数据库基础知识
  15. maven下载及安装教程(保姆及教程)
  16. SPSS统计描述分析
  17. (最新)天津各片区,各小区,各学校 对应关系,持续更新
  18. 梅科尔工作室E1-张冉-鸿蒙笔记2
  19. sqlmap工具使用手册
  20. 联盟CPS聚合联盟聚推客推广项目赚钱吗?揭秘有人月入10万+

热门文章

  1. mysql安装教程详细教程_mysql压缩包安装教程
  2. [Android] AdGuard「3.5.17」直装已激活高级版 去除烦人广告的拦截器
  3. 游戏运维linux,Linux运维知识之Linux的10个游戏
  4. java中MVC原理详解,SpringMVC运行原理,MVC的基本原理
  5. WPF空心圆角combox
  6. SpringBoot集成UEditor实现文本编辑功能增删查改发布等功能
  7. Note AI(记录爱) 智能写作平台,一款集成AI大模型的云笔记产品的系统设计
  8. mysql longblob,Mysql LONGBLOB 类型存储二进制数据 (修改+调试+整理)
  9. 一起学ORBSLAM2(11)ORBSLAM的localmapping
  10. 由双引号与单引号引起基础知识总结