android 8.0 以后的版本,在创建通知栏的时候,加了一个channelId的东西。要想在上述版本中显示通知,总共分两步

1.创建Channel

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  String channelId = "whatever"; //根据业务执行
  String channelName = "whatever conent"; //这个是channelid 的解释,在安装的时候会展示给用户看
  int importance = NotificationManager.IMPORTANCE_HIGH;
  createNotificationChannel(channelId, channelName, importance); }

2.引用

Notification notification = new Notification.Builder(this,"whatever") //引用加上channelid
  .setSmallIcon(R.drawable.donkey)
  .setWhen(System.currentTimeMillis())
  .setContentTitle("随便")
  .setContentText("随随便便写")
  .setContentIntent(pendingIntent)
  .build();

为了兼容android所有版本,最好在代码里做一下适配

manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

Intent intent = new Intent(this, AudioPlayerActivity.class);
intent.putExtra("Notifiction",true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  String channelId = "whatever"; //根据业务执行
  String channelName = "whatever conent"; //这个是channelid 的解释,在安装的时候会展示给用户看
  int importance = NotificationManager.IMPORTANCE_HIGH;
  createNotificationChannel(channelId, channelName, importance); } PendingIntent pendingIntent = PendingIntent.getActivity(this,1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = null;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){   notification = new Notification.Builder(this,"whatever") //引用加上channelid
    .setSmallIcon(R.drawable.donkey)
    .setWhen(System.currentTimeMillis())
    .setContentTitle("随便")
    .setContentText("随随便便写")
    .setContentIntent(pendingIntent)
    .build();
}else{
  notification = new Notification.Builder(this)
    .setSmallIcon(R.drawable.donkey)
    .setWhen(System.currentTimeMillis())
    .setContentTitle("随便")
    .setContentText("随随便便写")
    .setContentIntent(pendingIntent)
    .build();
} manager.notify(1,notification);

如何解决android 通知栏不显示的问题的更多相关文章

  1. 解决Android Studio 无法显示Layout视图问题

    在Android Studio 当中,如果你选择的SDK的版本 与你所显示的视图版本不一致时,会出现这个错误 Exception raised during rendering:com/android ...

  2. 解决Android Graphical Layout 界面效果不显示

    解决Android Graphical Layout 界面效果不显示 qq463431476

  3. 不完全解决Android微信HTML5 播放视频的问题(不显示控制条,可交互)

    首先你需要知道以下内容: http://ad.weixin.qq.com/learn/2-3-3--%E9%80%9A%E7%94%A8%E5%BA%93 这是微信为广告商开放的API,我一直认为只有 ...

  4. Android通知栏介绍与适配总结(上篇)

    此文已由作者黎星授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 由于历史原因,Android在发布之初对通知栏Notification的设计相当简单,而如今面对各式各样的通知 ...

  5. Android通知栏介绍与适配总结

    由于历史原因,Android在发布之初对通知栏Notification的设计相当简单,而如今面对各式各样的通知栏玩法,谷歌也不得不对其进行更新迭代调整,增加新功能的同时,也在不断地改变样式,试图迎合更 ...

  6. 解决 Android Studio 乱码问题

    http://www.eoeandroid.com/thread-275485-1-1.html 很多同学都安装了Android Studio,但是发现中文是乱码,其实这个很好解决的.在IDE里点击F ...

  7. Android --通知栏Notification

    参考博客:Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它) //创建一个通知栏的Builder构造类 (Create a Notification Bui ...

  8. Android 通知栏用法例子

    当程序意外退出时,可以去掉通知栏上显示的图标 1.创建TestNotificationActivity activity类, package com.notioni.test.notification ...

  9. Android在ListView显示图片(重复混乱闪烁问题)

    Android在ListView显示图片(重复混乱闪烁问题) 1.原因分析 ListView item缓存机制: 为了使得性能更优,ListView会缓存行item(某行相应的View). ListV ...

随机推荐

  1. C# 从字符串中提取指定字符类型的内容

    从一段字符串中,提取中文.英文.数字 中文字符30Margin中文字符40HorizontalAlignment 正则表达式: /// <summary> /// 英文字母与数字 /// ...

  2. SpringCloud服务配置中心

    SpringCloud Config简介 Spring Cloud Config 是 Spring Cloud 团队创建的一个全新项目,用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持 ...

  3. Angular(04)-知识点脑图

    点击左键 => 拖拽图片 => 新标签页查看图片 => 放大拖拽查阅

  4. 分析Android APK- smali 语言简介

    2.1 smali 语言简介 1.smali apk文件通过apktool反编译出来的都有一个smali文件夹,里面都是以.smali结尾的文件. smali语言是Davlik的寄存器语言,语法上和汇 ...

  5. simple go web application & 二维码生成 & 打包部署

    go语言简易web应用 & 二维码生成及解码 & 打包部署 转载请注明出处: https://www.cnblogs.com/funnyzpc/p/10801476.html 前言(闲 ...

  6. 编辑器之神vim的一些常用快捷键整理

    yy:复制 光标所在的这一行 4yy:复制 光标所在行开始向下的4行 p:粘贴 dd:剪切(删除) 光标所在的这一行 4dd:剪切(删除) 光标所在行向下的4行 D:从当前的光标开始向后剪切,一直到行 ...

  7. MyBatis PropertyTokenizer

    PropertyTokenizer package org.apache.ibatis.reflection.property; import java.util.Iterator; /* 例1: 参 ...

  8. 围观高手是如何写好 Python 循环,把内存用到极致的?

    0 前言 说到处理循环,我们习惯使用for, while等,比如依次打印每个列表中的字符: lis = ['I', 'love', 'python'] for i in lis:     print( ...

  9. Java题库——Chapter1 计算机、程序和Java概述

    1)________ is the physical aspect of the computer that can be seen. A)Hardware B) Operating system C ...

  10. 如何解决eclipse远程服务器上面的Rabbitmq连接超时问题?

    1.嗯,问题呢,就是一开始安装好RabbitMQ,练习了一下RabbitMQ的使用,但是呢,过了一段时间,我来复习的时候,发现运行出现下面的错误了.后来想想,是自己学习微服务的时候,修改了/etc/h ...