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# get folder's Md5 generated by file's and filename's md5. get dictionary md5

    C# get dictionary md5 static string GetDicMD5(string dirFullName) { logBuilder = new StringBuilder() ...

  2. mysql字符集与比较规则

    MySQL有4个级别的字符集和比较规则,分别是: 服务器级别 数据库级别 表级别 列级别 查看服务器级别命令: mysql> SHOW VARIABLES LIKE 'character_set ...

  3. Flask 教程 第十章:邮件支持

    本文翻译自The Flask Mega-Tutorial Part X: Email Support 这是Flask Mega-Tutorial系列的第十部分,在其中我将告诉你,应用如何向你的用户发送 ...

  4. 龙芯电脑上Electron应用开发

    背景 最近在一台龙芯电脑(系统是中兴新支点,Linux)上开发electron应用. PS:龙芯是国产的cpu,采用是mips架构,类似x86.arm. 安装NodeJS 安装步骤请查看:https: ...

  5. cesium 圆圈警戒扫描(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

  6. sql server使用sp_executesql返回拼接字符串里面的输出参数

    问题: 今天一同事请教博主,他拼接了一个语句,select表格形式数据,然后使用@@rowcount获取到行数. 但他又有这样特别的需求:想只获取行数而不返回表格数据结果,因为是while循环,不想返 ...

  7. August 11th, 2019. Week 33rd, Sunday

    Worry does not empty tomorrow of its sorrow. It empties today of its strength. 忧虑不会消除明天的痛苦,它只会削弱今天的力 ...

  8. php 判断空

    结果: 结论:$a != false 这种判断方式比empty() 速度更快

  9. jquery 获取元素(父节点,子节点,兄弟节点)

    费话不多说,直接上代码jquery 获取元素 $("#test1").parent(); // 父节点 $("#test1").parents(); // 全部 ...

  10. Appium+Java 自动化测试系列二:Maven+Testng

    新建Maven项目作为测试项目分为3个步骤: 1.Eclipse安装Testng 插件 2.新建Maven项目 3.引入Testng 一.Eclipse安装Testng插件 TestNG安装可选择在线 ...