在 Android O 以后,Google引入了通知通道的概念,如果目标API大于 Android O ,不直指定通知渠道是不能发送通知的。

这里放一个我写好的通知方法,大家可以适当的改改再用,*当然亦可以直接用*

    /**
* 通过通知渠道发送通知 Android O 新增API
* 其他的还和以前一样
*
* @param channelID 渠道ID
* @param channelName 渠道名字
* @param subText 小标题
* @param title 大标题
* @param text 内容
*/
@TargetApi(Build.VERSION_CODES.O)
public void sendNotification(String channelID, String channelName, String subText, String title, String text) { //创建通道管理器
NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH); NotificationManager manager;
manager = (NotificationManager) this.getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel); //构建通知
Notification.Builder builder = new Notification.Builder(getApplicationContext());
//设置小图标
builder.setSmallIcon(R.mipmap.ic_launcher);
//设置通知 标题,内容,小标题
builder.setContentTitle(title);
builder.setContentText(text);
builder.setSubText(subText);
//设置通知颜色
builder.setColor(Color.parseColor("#E91E63"));
//设置创建时间
builder.setWhen(System.currentTimeMillis());
//创建通知时指定channelID
builder.setChannelId(channelID); Intent resultIntent = new Intent(this, ClipActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent); //构建一个通知,最后通知管理器 发送
Notification notification = builder.build();
manager.notify(1, notification);
}

Android O的通知渠道适配的更多相关文章

  1. 适配 通知 Notification 通知渠道 前台服务 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  2. Android 普通通知栏新方法,现在需要创建通知渠道才可以

    先看看效果看看是不是你想要的 点击后 话不多所,贴代码 xml文件: <?xml version="1.0" encoding="utf-8"?>& ...

  3. Android 8.0+ 通知不显示的适配

    最近在 写项目的时候  发现 通知并不会显示的问题,查看资料发现 从Android 8.0开始通知必须加上ChannelId Android O 引入了 通知渠道(Notification Chann ...

  4. Android Notification 消息通知 相关资料.md

    目录 Android Notification 消息通知 相关资料 Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题 解决方案 参考 ...

  5. Android 13 新特性及适配指南

    Android 13(API 33)于 2022年8月15日 正式发布(发布时间较往年早了一些),正式版Release源代码也于当日被推送到AOSP Android开源项目. 截止到笔者撰写这篇文章时 ...

  6. Android中的通知—Notification 自定义通知

    Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...

  7. Android推送通知指南

      Android推送通知指南 在开发Android和iPhone应用程序时,我们往往需要从服务器不定的向手机客户端即时推送各种通知消息,iPhone上已经有了比较简单的和完美的推送通知解决方案,可是 ...

  8. Python 制作Android开发 所需的适配不同分辨率的套图

    使用Python做起工具来还真是爽,简单,方便,快捷.今天忙活了一下,制作出一个比较实用的小工具. 自动化套图制作,适配不同屏幕 尤其是对于android开发来说,要适配不同屏幕就需要多套切图,那么. ...

  9. Android开发——Notification通知的各种Style详解

    本来是想与之前讲解使用Notification通知使用一起写的,查看了资料,觉得有必要将这Style部分单独拿出来讲解 前篇:Android开发——Notification通知的使用及Notifica ...

随机推荐

  1. vscode解决nuget插件不能使用的问题

    错误提示 使用vscode安装nuget插件之后出现错误: "Versioning information could not be retrieved from the NuGet pac ...

  2. openstack 搭建

    #所有节点修改ip,主机名和hosts解析 controller 10.0.0.11 controller compute1 10.0.0.31 compute1 #所有节点准备本地repo源 rm ...

  3. Python Web(二)

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.Django-debug-toolbar django-debug-toolbar 是一组可配置的面板,可显示 ...

  4. 百度地图API----搜索地址,获取该点的位置坐标并转换成WebMercator

    function doFind(){ LoadBaiduMapScript().then(BaiduMap).then(function () { //查询并获取坐标 var myGeo = new ...

  5. angularjs 实现猜数字大小的功能

    <body ng-app="myapp" ng-controller="myCtrl"> <h2>猜一猜,多大值?(1-1000)< ...

  6. 安装 tensorflow 1.1.0;以及安装其他相似版本tensorflow遇到的问题;tensorflow 1.13.2 cuda-10环境变量配置问题;Tensorflow 指定训练时如何指定使用的GPU;

    # 安装 2.7 环境conda create -n python2. python= conda activate python2. # 安装 1.1.0 gpu版本pip # 配置环境变量expo ...

  7. Re-stheasy

    https://dn.jarvisoj.com/challengefiles/ctf2.b93676be23733b2fcda3988c1133c1c1 用IDA-32bit 打开,找到main函数 ...

  8. UVA 12165 Triangle Hazard

    https://cn.vjudge.net/problem/UVA-12165 题目 给出D.E.F分BC,CA,AB的比$m_1:m_2$,$m_3:m_4$,$m_5:m_6$和PQR三点的坐标, ...

  9. UVA1401 Remember the word DP+Trie

    问题描述 洛谷(有翻译) 题解 DP,设\(opt_i\)代表前\(i\)个字符方案数. Trie优化,刷表法. \(\mathrm{Code}\) #include<bits/stdc++.h ...

  10. [BZOJ1042]AOI2008]硬币购物

    题目描述 Description 硬币购物一共有4种硬币.面值分别为\(c_1\) ,\(c_2\) ,\(c_3\) ,\(c_4\) .某人去商店买东西,去了\(tot\) 次.每次带\(d_i\ ...