直接代码,demo复制到一个新的activity可用

android 9.0,设置对应手机弹窗方式即可
package com.example.administrator.myapplication;import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;import static android.app.Notification.BADGE_ICON_SMALL;
/*** @author Administrator*/
public class MainActivity extends AppCompatActivity {private NotificationManager mNotificationManager;private String groupId = "groupId";private CharSequence groupName = "Group1";private String groupId2 = "groupId2";private CharSequence groupName2 = "Group2";private String chatChannelId2 = "chatChannelId2";private String adChannelId2 = "adChannelId2";private String chatChannelId = "chatChannelId";private String chatChannelName = "聊天通知";private String chatChannelDesc = "这是一个聊天通知,建议您置于开启状态,这样才不会漏掉女朋友的消息哦";private int chatChannelImportance = NotificationManager.IMPORTANCE_MAX;private String adChannelId = "adChannelId";private String adChannelName = "广告通知";private String adChannelDesc = "这是一个广告通知,可以关闭的,但是如果您希望我们做出更好的软件服务于你,请打开广告支持一下吧";private int adChannelImportance = NotificationManager.IMPORTANCE_LOW;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);createGroup();notification();}public void notification() {createNotificationChannel(chatChannelId, chatChannelName, chatChannelImportance, chatChannelDesc, groupId2);Notification.Builder builder = null;if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {builder = new Notification.Builder(this, chatChannelId);builder.setSmallIcon(R.mipmap.ic_launcher).setContentTitle("我是标题").setContentText("内容:Today released Android 8.0 version of its name is Oreo").setBadgeIconType(BADGE_ICON_SMALL).setNumber(1).setAutoCancel(true);Intent resultIntent = new Intent(this, MainActivity.class);TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);stackBuilder.addParentStack(MainActivity.class);stackBuilder.addNextIntent(resultIntent);PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);builder.setContentIntent(resultPendingIntent);mNotificationManager.notify((int) System.currentTimeMillis(), builder.build());}}public void notification2() {createNotificationChannel(adChannelId, adChannelName, adChannelImportance, adChannelDesc, groupId2);Notification.Builder builder = null;if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {builder = new Notification.Builder(this, adChannelId);builder.setSmallIcon(R.mipmap.ic_launcher).setContentTitle("我是广告").setContentText("内容:恰饭时间到了,Oreo is Coming.").setBadgeIconType(BADGE_ICON_SMALL).setNumber(1).setAutoCancel(true);Intent resultIntent = new Intent(this, MainActivity.class);TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);stackBuilder.addParentStack(MainActivity.class);stackBuilder.addNextIntent(resultIntent);PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);builder.setContentIntent(resultPendingIntent);mNotificationManager.notify((int) System.currentTimeMillis(), builder.build());}}public void createNotificationChannel(String id, String name, int importance, String desc, String groupId) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {if (mNotificationManager.getNotificationChannel(id) != null) {return;}NotificationChannel notificationChannel = new NotificationChannel(id, name, importance);notificationChannel.enableLights(true);notificationChannel.enableVibration(true);notificationChannel.setLightColor(Color.RED);notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);notificationChannel.setShowBadge(true);notificationChannel.setBypassDnd(true);notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400});notificationChannel.setDescription(desc);notificationChannel.setGroup(groupId);
//        notificationChannel.setSound();mNotificationManager.createNotificationChannel(notificationChannel);}}public void delNotification(View view) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {mNotificationManager.deleteNotificationChannel(chatChannelId);}}public void delNotification2(View view) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {mNotificationManager.deleteNotificationChannel(adChannelId);}}public void setting(View view) {Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);intent.putExtra(Settings.EXTRA_CHANNEL_ID, chatChannelId);intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());startActivity(intent);}public void createGroup() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId, groupName));mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId2, groupName2));createNotificationChannel(chatChannelId2, chatChannelName, chatChannelImportance, chatChannelDesc, groupId);createNotificationChannel(adChannelId2, adChannelName, adChannelImportance, adChannelDesc, groupId);}}public void delNotificationGroup(View view) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {mNotificationManager.deleteNotificationChannelGroup(groupId2);}}}

具体可查看:http://gavinliu.cn/2017/08/22/Android-吃奥利奥系列-1-Notification/

android 9.0通知栏适配,可用通知栏,悬浮通知,震动,提示音,相关推荐

  1. android8 测试,Android 8.0 Oreo 国内可用测试平台上线

    原标题:Android 8.0 Oreo 国内可用测试平台上线 Android 8.0 Oreo 已经发布一个月了,无数开发者已经跃跃欲试,想在这个全新版本的 Android 系统上让自己的应用一展身 ...

  2. android关闭触摸提示音,Android取消和开启View或则ViewGroup点击带有提示音

    前言 如果系统设置[声音]选项中关闭了[触摸提示音],则所有的View都没有提示音. 开启系统设置[触摸提示音]基础上,View或ViewGroup设置setOnTouchListener()或者se ...

  3. Android 8.0 极光推送通知栏显示 ’xxx正在运行‘

    场景 Android系统8.0及以上,开启Service必须使用startForegroundService(Intent intent)方法,对应的Service则必须设置startForegrou ...

  4. Android 9.0 简单适配

    转载请声明,本文来自: 本文仅描述当前项目apk遇到的适配9.0问题,所以不是全面的,请自行参考: 适配一: 纯后台服务,需要在AndroidManifest.xml添加权限 <uses-per ...

  5. 华为android8适配进度,华为 荣耀 O版本(Android 8.0)适配进度公告

    [官方活动] 华为 & 荣耀 O版本(Android 8.0)适配进度公告 109470826 电梯直达 青牛 城市花部长 发表于 2017-10-26 16:47:42 来自:浏览器 最新回 ...

  6. Android 8.0 Oreo 国内可用测试平台上线

    Android 8.0 Oreo 已经发布两个月了,无数开发者已经跃跃欲试,想在这个全新版本的 Android 系统上让自己的应用一展身手,我们很清楚,Android 8.0 为了更流畅的系统,以及更 ...

  7. android 9.0 https 适配,如何适配 Android 9.0? 在 Android 9.0 上发生 SSL handshake timed out 异常怎么解决...

    Android 9.0 开始,默认不允许明文传输,所以在建立网络连接时会使用 https 连接,同时进行安全认证.如果应用没有做对应处理,即会发生上述异常. 解决方法有两种: 一. 在应用里声明允许明 ...

  8. APP分享多张图片和文字到微信朋友圈(android 7.0以上适配)

    1.微信平台没有提供分享多张图片的SDK,我们只能自己调用系统自带的分享功能实现. 2.实际分享的时候因为是调用系统本地的分享功能,所以分享的图片也就必须要存到本地,不然就会提示获取资源失败而导致分享 ...

  9. android 5.0按钮不可用,Android 5.0 教程:解决 Smart Lock 不能正常工作问题

    Smart Lock 是 Andoird 5.0 新引入的智能解锁方案,它可以在信任的蓝牙/NFC 设备.地点实现免密码解锁,关于 Smart Lock 的详细功能介绍大家可参阅这篇文章.这个功能一经 ...

  10. Android仿QQ锁屏状态下消息提醒(震动+提示音)

    导读: 最近在开发一个定时提醒业务,类似于闹钟,然后遇到了一个问题,当APP应用在后台运行时,用户关闭了手机屏幕(手机进入灭屏休眠状态),这个时候使用系统震动和闹钟没有起到作用.why? 同样是灭屏休 ...

最新文章

  1. Java项目:前台+后台精品图书管理系统(java+SSM+jsp+mysql+maven)
  2. 虚拟化 php性能测试,KVM的一些基准测试和性能测试数据分享
  3. boost::hana::sizeof_用法的测试程序
  4. 表达能力VS只会敲代码(2018届毕业生web前端)
  5. Cisco Adsl 详细配置
  6. VSCode + git 代码托管【当前没有源代码管理提供程序注册】(没有‘+’加法号) - 解决篇
  7. SAP HANA如何在存储过程中使用自定义的table type
  8. Python 扩展C
  9. 基于springboot的家政服务网站
  10. grub4dos 加载 MEMTEST+86
  11. 应用在AVR上的拼音输入法
  12. 四非到保研厦大,我们还有多少路要走----技术人的保研之路
  13. 手写demo了解vue响应式原理,订阅模式,观察者模式
  14. android 模拟器介绍
  15. java 判断经纬度_Java中根据经纬度来判断距离
  16. 解决VS编译生成的exe文件不能在其他电脑上运行的问题
  17. 关于c#,PHP socket挂到云服务器上之后本机无法连接的问题
  18. vgg16网络模型的学习理解
  19. 树莓派开机自启动opencv程序脚本及报错分析及拓展
  20. 草图logo绘画演绎AE模板

热门文章

  1. dota2 服务器尚未更新到最新版本,DOTA2更新不了怎么办 如何解决这些疑难杂症
  2. 神秘!迅雷将推共享计算企业级新品
  3. 开发淘宝开放平台中的B端或者C端小程序,后端调用api使用的sessionKey如何获取?
  4. Discuz搬家教程
  5. 好声音”杨坤组大森蝶晋级 被传与刘珂有恋情
  6. sitemap php 生成,php自动生成sitemap
  7. 2019计算机软件技术的就业率是多少,2019计算机科学与技术专业就业方向与就业前景如何...
  8. ASP.NET发送邮件(同步、异步)
  9. Mastercam2022程序单升级版
  10. 美洽发送离线消息到开发者服务器