Android Notification 消息通知 相关资料

Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题

解决方案

详情见参考资料2.

  1. 使用在线PS 去掉原来图标的背景色,保留主题图标为白色

    Photopea | Online Photo Editor
  2. 打开 Android Asset Studio Notification icon generator 然后上传新LOGO
  3. 下载 处理好后的新图标即可.

    android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.mipmap.ic_launcher_white : R.mipmap.ic_launcher

参考资料

  1. Android 5.0 行为变更 | Android Developers

    在白色(或非常浅)的背景上使用深色文本绘制通知,以便与新的 Material Design 小部件匹配。请确保您的所有通知都与新的配色方案协调一致。如果您的通知看上去不协调,请进行修正:

    • 使用 setColor() 在您的图标图像后面的圆形中设置重点色彩。
    • 更新或移除使用色彩的资源。系统在操作图标和主要通知图标中忽略所有非阿尔法通道。您应假设这些图标仅支持阿尔法通道。系统用白色绘制通知图标,用深灰色绘制操作图标。
  2. Android Push Notifications: Icon not displaying in notification, white square shown instead - Stack Overflow

    • For 5.0 Lollipop "Notification icons must be entirely white".
    Notification notification = new NotificationCompat.Builder(this);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notification.setSmallIcon(R.drawable.icon_transperent);
    notification.setColor(getResources().getColor(R.color.notification_color));
    } else {
    notification.setSmallIcon(R.drawable.icon);
    }
    • I found a link where we can generate our own white icon,

      try this link to generate white icon of your launcher icon.

      Open this Link Android Asset Studio and upload your ic_launcher or notification icon
  3. android 5.0以上通知栏、状态栏图标变成白色 - 晕菜一员 - 博客园

    因为google在android5.0上面做了限制,为了统一系统风格。之后的状态栏icon就不能够随便用一张色彩丰富的图片了,只能够有白色和透明两个颜色出现。

    5.0以上(不包含5.0),系统默认通知栏图标为系统启动图标,会自动将通知栏的图标(有色区域)全部填充为白色,

  4. Android 的 notification 图标问题 - V2EX

    因为原先的那种形式的图标不好看, 颜色太花, 在状态栏上一点也不好看.

    并且这也是 Material Design 的规范了 ( https://www.google.com/design/spec/patterns/notifications.html) 实际上这样的改变在 Android 5.0 里好看了很多,

    如果你看到有些厂商还不知道的, 那么就是他们菜或者是上班混日子.

Android 8.0 Oreo(API 26) 及更高版本 如何更新 消息通知渠道 设置的问题

解决方案:无!

谷歌官方文档说明了,一旦渠道创建完毕,那么最终管理权利就移交给用户了. 程序最多可以将其删除, 想修改是不可能的了.

ByYe:间接解决方案=根据title或者sound的不同,创建不同的渠道.来间接实现.

问题详情

想重用一个渠道, 只是修改不同的部分,比如提示声音铃声不同.

参考资料

  1. https://developer.android.com/guide/topics/ui/notifiers/notifications#limits

    发布限制

    从 Android 8.1(API 级别 27)开始,应用无法每秒发出一次以上的通知提示音。如果应用在一秒内发出了多条通知,这些通知都会按预期显示,但是每秒中只有第一条通知发出提示音。

    不过,Android 还对通知更新频率设定了限制。如果您过于频繁地发布有关某条通知的更新(不到一秒内发布多个),系统可能会放弃部分更新。

  2. How to properly update notification channel android oreo - Stack Overflow

    Once a notification channel is created, the user has ultimate control over it's settings.

    As the developer, you can only change the channel's title and description.

    If you want to recreate the channel, you have to use a different id.

    See: https://developer.android.com/training/notify-user/channels

  3. Create and Manage Notification Channels | Android Developers

    • Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel
    • After you create a notification channel, you cannot change the notification behaviors—the user has complete control at that point. Though you can still change a channel's name and description.
    • But remember that once you create the channel, you cannot change these settings and the user has final control of whether these behaviors are active.
  4. Android Oreo 通知新特性,这坑老夫先踩了 - 简书

    其中“lockscreenVisibility”和“setBypassDnd”是无法生效的,因为从源码中来看,

    只能被系统或排序服务(Android Notification Ranking Service)更改。

Android 7.0 Nougat(API 24) 及更高版本 消息通知 设置的自定义铃声 无法正常播放问题

解决方案

  1. 详情参见 参考资料1
  2. 采用的是使用自定义ContentProvider The Axe: Use a Custom ContentProvider
  3. 实际测试效果: Android 8.1 + Android 4.4.4 版本都正常.

解决步骤:

  1. 下载最新版本的cwac-provider-0.5.3.jar并集成到项目中

    GitHub - commonsguy/cwac-provider: CWAC-Provider: Helping to Make Content Providers Sane

  2. 按文档要求在清单文件里AndroidManifest.xml添加了以下代码:

    <provider
    android:name="com.commonsware.cwac.provider.StreamProvider"
    android:authorities="${applicationId}.DataFilesSoundsStreamProvider"
    android:exported="true">
    <meta-data
    android:name="com.commonsware.cwac.provider.STREAM_PROVIDER_PATHS"
    android:resource="@xml/data_files_sounds_paths" />
    </provider>
  3. 在项目资源目录里添加了res/xml/data_files_sounds_paths.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <paths>
    <files-path
    name="data_files_sounds"
    path="sounds"
    readOnly="true" />
    </paths>
  4. 将代码中原使用Uri.fromFile(file)的地方替换为com.commonsware.cwac.provider.StreamProvider.getUriForFile(mContext.getPackageName() + ".DataFilesSoundsStreamProvider", file)即可

问题详情

问题还原步骤:

  1. 使用 NotificationCompat.Builder.setSound 设置自定义铃声
  2. 自定义铃声 位于 SDCard外置存储卡Environment.getExternalStorageDirectory() 某个目录里.

结果:

  1. Android 6 之前的版本 正常 播放.

  2. Android 7 以后的版本 无法 播放.

    抛出异常:StrictMode: file:// Uri exposed through Notification.sound

参考资料

  1. java - Android 7.0 Notification Sound from File Provider Uri not playing - Stack Overflow

    If you were using file: Uri values, they no longer work on Android 7.0 if your targetSdkVersionis 24 or higher, as the sound Uri is checked for compliance with the ban on file: Uri values.

    假如你还在使用file:uri形式的路径值, 那么Android 7.0以后的版本就不再支持了(只要targetSdkVersion > 24)

    However, if you try a content: Uri from, say, FileProvider, your sound will not be played... because Android does not have read access to that content.

    但是,假如你尝试使用content: 开头的Uri对象,例如通过FileProvider可以拿到这类对象,结果你的自定义通知铃声还是不能正常播放囧。原因是Android系统本身没有你指定的文件的读取权限

    解决方案有:

    1. 使用grantUriPermissions()授权,让其具有读取权限The Scalpel: grantUriPermissions()

      grantUriPermission("com.android.systemui", soundUri,Intent.FLAG_GRANT_READ_URI_PERMISSION);

      缺点: 在于你不知道给授权,Android默认会是com.android.systemui,至于其它厂商的系统是不是这个,就很难说了.

      Thanks a lot for the thorough answer. To verify the robustness of the grantUriPermission solution ('The Scalpel'), I've tested it in different physical devices (including LG, Motorola, HTC, Samsung and Sony), from API 15 up to API 24. It works correctly on all of them, so the solution seems pretty solid (although certainly hacky). – jmart Sep 7 '16 at 18:24

    2. 不提供完全自定义的铃声,仅仅提供部分可选择的铃声 The Guillotine: No More User Files

      原因是:android.resource开头的Uri对象路径Android系统默认是支持直接读取的,所以只要将部分可供选择的铃声放在APP的RAW资源目录里即可.

      缺点:在于让用户无法完全自定义自己的铃声了,可能你的用户不一定会买账.

    3. 使用自定义ContentProvider The Axe: Use a Custom ContentProvider

      FileProvider 不能直接用,因为一旦设置成 exported 那么一启动APP就会崩溃.

      那么可用的方案就是自定义一个支持exported且具有读取权限的 ContentProvider了.

      可以参见: GitHub - commonsguy/cwac-provider: CWAC-Provider: Helping to Make Content Providers Sane

      Using a read-only ContentProvider (see "The Axe") is the better answer. I'll probably rig up my StreamProvider such that if you mark it as exported, it treats everything as read-only, which would handle this problem fairly cleanly. – CommonsWare

Android Notification 消息通知 相关资料.md的更多相关文章

  1. cordova的android notify消息通知插件

    最近在学习用CORDOVA(PHONEGAP)结合SENCHA TOUCH开发应用,想实现一个安卓下的消息通知功能,这个可以通过CORDOVA的插件来实现. 插件目录结构如下: notifyplugi ...

  2. Android Notification状态栏通知

    没有添加额外的震动及声音效果,这里直接实现了通知的功能,看效果吧: MainActivity.java package com.example.notification; import android ...

  3. Android (Notification)消息推送机制

    从网上查询资料学习Android消息推送机制,效果图如下: 1.首先是布局文件代码 activity_main.xml <?xml version="1.0" encodin ...

  4. Android Notification实现推送消息过程中接受到消息端有声音及震动及亮屏提示

    在Android Notification状态栏通知一文中,简单实现了消息的推送效果,这里就接着上文说一下,当用户接受到消息时的提示效果 // 5-增加震动及声音及亮屏 notification.de ...

  5. Android中的消息通知(NotificationManager和Notification)

    下面来谈谈notification,这个notification一般用在电话,短 信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这 ...

  6. Android消息通知(notification)和PendingIntent传值

    通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...

  7. Android消息通知-Notification

    Android中常用的消息提醒,一种是Toast弹出提醒内容,一种是AlterDialog弹出框来提醒用户,还有一种就是消息通知的,用Android经常收到各种通知就是Notifation.Notif ...

  8. Android学习总结(十五) ———— Notification(状态栏通知)基本用法

    一.Notification基本概念  Notification是一种具有全局效果的通知,它展示在屏幕的顶端,首先会表现为一个图标的形式,当用户向下滑动的时候,展示出通知具体的内容.我们在用手机的时候 ...

  9. Android Notification通知详解

    根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面把notification放在通知栏里,再此显示时 ...

随机推荐

  1. 安装python包时出现VC++ 错误的解决方案

    方式一 就是按照提示在微软的官网上下载宇宙第一编辑器VS,安装完之后卸载掉就好了. 方式二 下载whl包安装 因为python有很多native的包,不是纯python代码,用了诸如c/c++的代码, ...

  2. String类-StringBuffer类-StringBuilder类的比较

    package LC20130929; /**  * 字符串处理类: StringBuffer ~~ StringBuilder 〉〉 String   效果一样但是,性能却大不一样!         ...

  3. cmake学习笔记之add_library、target_link_libraries和link_directories

    cmake是Linux(这里默认是Ubuntu系统)下常使用的编译C++的工具,而使用cmake就需要先在CmakeLists.txt文件中对编译规则进行.这里介绍常用的三种指令add_library ...

  4. java动态代理框架

             java动态代理是一个挺有意思的东西,他有时候可以被使用的很灵活.像rpc的调用,调用方只是定义的一个接口,动态代理让他匹配上对应的不同接口:mybatis内部的实现,编码时,只是实 ...

  5. appium自动化 - android

    1. 获取driver appium通过生成driver来识别和操作app的UI元素.生成driver时,需要给出被测设备的相关信息.appium官方上的例子如下: https://github.co ...

  6. MyBatis中#{}和${}的不同和${}的妙用(转)

        突然意识到sql语句的独特语义要和代码分离,我们就不能够在代码中写sql语句!!比如我要用${}在MyBatis的sql中拼接排序类型的时候,我就不能够在Java代码中直接写参数字符串为Ord ...

  7. 删除3天前创建的以log结尾的文件

    1. #/bin/bash # filename: del_log.sh find / -name "*.log" -mtime 3 | xargs rm -rf 2. #/bin ...

  8. laravel Passport - Dingo/Api v2.0+Passport 实现 api 认证

    第一部分: 安装passport 使⽤ Composer 依赖包管理器安装 Passport : composer require laravel/passport 接下来,将 Passport 的服 ...

  9. TextRCNN 文本分类 阅读笔记

    TextRCNN 文本分类 阅读笔记 论文:recurrent convolutional neural networks for text classification 代码(tensorflow) ...

  10. Django-视图函数/模板渲染/过滤器

    一.Django的视图函数 一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受Web请求并且返回Web响应. 响应可以是一张网页的HTML内容,一个重定向,一个404错误,一个 ...