網(wǎng)站首頁 編程語言 正文
前言
目前各個市場都要求targetsdkversion要不低于26,也就是android 8.0。 相應(yīng)的影響很多功能,比如通知。
當(dāng)targetsdkversion >= 26,需要為通知添加channel,如
manager = (NotificationManager) BaseApp.getAppContext() .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel("update", "update", NotificationManager.IMPORTANCE_DEFAULT); manager.createNotificationChannel(channel); } builder = new NotificationCompat.Builder(BaseApp.getAppContext(), "update");
首先要新建一個NotificationChannel,并調(diào)用NotificationManager的createNotificationChannel啟用該通道。
然后在創(chuàng)建buidler的時候設(shè)置同樣的channelid即可。
靜音
那么如果想讓通知靜音怎么處理?
- 可以在channel上設(shè)置,
setSound(null, null)
。注意如果已經(jīng)安裝且這個channel已經(jīng)存在,再覆蓋安裝不能生效,需要卸載重裝。 - 也可以對builder進(jìn)行設(shè)置,
setOnlyAlertOnce(true)
。注意這個并不是完全靜音,而是讓這個通知只響一次,比如顯示下載進(jìn)度時,就不會一直響。
manager = (NotificationManager) BaseApp.getAppContext() .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel("update", "update", NotificationManager.IMPORTANCE_DEFAULT); channel.setSound(null, null); manager.createNotificationChannel(channel); } builder = new NotificationCompat.Builder(BaseApp.getAppContext(), "update"); ... builder.setOnlyAlertOnce(true);
總結(jié)
原文鏈接:https://juejin.cn/post/7062616850005229582
相關(guān)推薦
- 2022-07-29 pytest解讀fixture有效性及跨文件共享fixtures_python
- 2022-09-03 Python?Pandas多種添加行列數(shù)據(jù)方法總結(jié)_python
- 2022-10-22 PyTorch中的CUDA的操作方法_python
- 2022-09-03 Python實現(xiàn)求解最大公約數(shù)的五種方法總結(jié)_python
- 2022-06-04 Kubernetes中Deployment的升級與回滾_云和虛擬化
- 2022-07-13 簡單的利用boost.python 和 boost.numpy 實現(xiàn)python和c++之間數(shù)據(jù)通信
- 2022-08-15 LCP創(chuàng)建bond接口
- 2023-01-07 Python源碼加密與Pytorch模型加密分別介紹_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支