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. jquery 实现只能选中一个checkbox,选中当前的去除上一个

    jq 实现只能选中一个checkbox,选中当前的去除上一个. <div id="checkboxed"> <input name="check1&qu ...

  2. [转]Python十个高大上的语法

    Python 是一种代表简单思想的语言,其语法相对简单,很容易上手.不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了.本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并 ...

  3. MySQL Error Log 文件丢失导致The server quit without updating PID file启动失败的场景

    今天在做mysql sniff测试的时候,中间重启MySQL实例的过程中,出现了"The server quit without updating PID file"这个经典的错误 ...

  4. windows重装系统后grub引导菜单修复方法(亲自实验过)

    问题: 电脑安装的是windows7+ubuntu 15.10双系统.windows重装后,grub引导界面消失. 解决方法有两大步: 1.进入ubuntu; 2.在ubuntu中修复grub. 一. ...

  5. centos8 安装 nginx

    http://nginx.org/ NGINX官网 创建文件夹mkdir nginx进入创建的文件夹 根据自己需要下载合适版本 通过 wget http://nginx.org/download/ng ...

  6. [译]Vulkan教程(30)深度缓存

    [译]Vulkan教程(30)深度缓存 Depth buffering 深度缓存 Introduction 入门 The geometry we've worked with so far is pr ...

  7. Flutter中高级培训

    Flutter中高级培训 一.简介 Flutter是谷歌的移动UI框架,可以快速在iOS和Android上构建高质量的原生用户界面.Flutter可以与现有的代码一起工作.本课程全面介绍Flutter ...

  8. ubuntu下面安装nodejs

    对于刚接触ubuntu的同学来说,一切都是新的,一切都是那么熟悉而又不熟悉的.不管是作为一个前端工程师还是一个后端工程师,我相信大家知道nodejs,但是如果希望自己能够在ubuntu上面使用node ...

  9. laravel实现多模块

    一.这里使用Caffienate Modules 网址:modules maintained by caffeinated 二.根据自己的版本选择包的版本 三.在项目composer.json文件中加 ...

  10. go面向对象之多态即接口(interface)

    Go 语言接口 Go 语言提供了另外一种数据类型即接口,它把所有的具有共性的方法定义在一起,任何其他类型只要实现了这些方法就是实现了这个接口. 实例 /* 定义接口 */ type interface ...