0
点赞
收藏
分享

微信扫一扫

Android Q 使用通知栏消息

晗韩不普通 2022-06-23 阅读 62
String myChannelId = "iot";
String myChannelName = "告警通知服务";
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(myChannelId, myChannelName,
NotificationManager.IMPORTANCE_LOW);
Toast.makeText(this, myChannelId, Toast.LENGTH_SHORT).show();
manager.createNotificationChannel(channel);
notification = new NotificationCompat.Builder(this, myChannelId)
.setContentTitle("测试")
.setContentText("一个新消息")
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.build();
}else {
notification = new NotificationCompat.Builder(this, myChannelId)
.setContentTitle("This is a title")
.setContentText("This is a context")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.build();
}
manager.notify(1, notification);

【版权声明】本博文著作权归作者所有,任何形式的转载都请联系作者获取授权并注明出处!

【重要说明】本文为本人的学习记录,论点和观点仅代表个人而不代表当时技术的真理,目的是自我学习和有幸成为可以向他人分享的经验,因此有错误会虚心接受改正,但不代表此刻博文无误!

【Gitee地址】秦浩铖:​​https://gitee.com/wjw1014​​


举报

相关推荐

Android 通知栏使用总结

0 条评论