《Android第一行代码(第2版)》中8.2节使用通知,MainActivity中使用:

Notification.Builder builder = new Notification.Builder(this, "channel_1");                Notification notification =                        builder.setContentTitle("This is content title")                                .setContentText("This is content text")                                .setWhen(System.currentTimeMillis())                                .setSmallIcon(R.mipmap.ic_launcher)                                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))                                .setAutoCancel(true)                                .setContentIntent(pi)                                .build();

测试机为Android8.0.0版本,发现无法运行,查看文章得知Android Oreo的通知写法与Android 7有所不同,正确写法为:

Notification.Builder builder = new Notification.Builder(this, "channel_1");                Notification notification =                        builder.setContentTitle("This is content title")                                .setContentText("This is content text")                                .setWhen(System.currentTimeMillis())                                .setSmallIcon(android.R.drawable.stat_notify_more)                                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))                                .setAutoCancel(true)                                .setContentIntent(pi)                                .build();

通知兼容写法参考:

http://blog.csdn.net/z642385985/article/details/78583980?locationNum=9&fps=1

另外,取消系统状态上的通知图标方法,本书中提到两种方法,但经测试后,只有一种方法可用:

.setAutoCancel(true)



更多相关文章

  1. android隐藏以及显示软键盘以及不自动弹出键盘的方法
  2. Android 常用画图方法练习
  3. android TextView setEms 方法名字
  4. Android级联菜单的实现方法
  5. Android实现手机震动抖动效果的方法
  6. android获取设备屏幕大小的方法
  7. Android中MediaPlayer的setDataSource方法的使用

随机推荐

  1. win8安装sql server2005方法
  2. sqoop简单操作-从mysql导入导出数据
  3. vs2012利用MFC开发基于对话框的小软件指
  4. 访问SqlServer时需要先登录服务器windows
  5. SQL问题 ,要连接两个无直接关联表
  6. 1)如何用语句来查看一个表内是否建了索引
  7. Scripts:创建手工的SQL PROFILE的脚本,老
  8. 求一SQL语句(如何按某列的值分组且取出每
  9. 高手是怎样炼成的:精妙SQL语句介绍
  10. 手把手教你mysql(十五)游标变量流程控制