android | 使用系统通知服务
android | 使用系统通知服务
小细节:8.0以上的安卓版本需要先注册通道
贴代码:
注册通知:
// init notification manager
nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// over 8.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel nChannel = new NotificationChannel("Mz1notice", "测试通知", NotificationManager.IMPORTANCE_HIGH);
nManager.createNotificationChannel(nChannel);
}
notice = new NotificationCompat.Builder(this, "Mz1notice")
.setContentTitle("标题")
.setContentText("文本")
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.icon))
.setSmallIcon(R.drawable.ic_nitice)
.setAutoCancel(true)
.build(); // create notice
发送通知:
nManager.notify(1, notice);
本文来自博客园,作者:Mz1,转载请注明原文链接:https://www.cnblogs.com/Mz1-rc/p/15860365.html
如果有问题可以在下方评论或者email:mzi_mzi@163.com
分类:
android
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
2021-02-02 re | [ACTF新生赛2020]fungame