private fun createNotificationChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channelName = getString(R.string.app_name)
val descriptionText = getString(R.string.channel_description)
val channel = NotificationChannel(
NotificationID.CHANNEL_ID,
channelName,
NotificationManager.IMPORTANCE_MIN
).apply {
description = descriptionText
}
channel.enableLights(false)
channel.enableVibration(false)
channel.setSound(null, null)
channel.setShowBadge(false)
notificationManager.createNotificationChannel(channel)
}
}
fun createNotification() {
val notificationCustomView = notificationCustomView(R.layout.notification_show)
val notification = NotificationCompat.Builder(this, NotificationID.CHANNEL_ID)
.setSmallIcon(R.mipmap.icon)
.setLargeIcon( BitmapFactory.decodeResource(
resources,
R.mipmap.icon
))
.setCustomBigContentView(notificationCustomView)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setGroupSummary(false)
.setGroup( getString(R.string.app_name))
.setContent(notificationCustomView)
.setAutoCancel(false)
.setSilent(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setOngoing(true) //通知栏常驻
.build()
with(NotificationManagerCompat.from(this)) {
notify(NotificationID.NOTIFICATION_ID, notification)
}
}
Android发送个普通自定义常驻通知
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 集成极光推送使用jcenter 自动集成步骤说明 : 使用 jcenter 自动集成,不需要在项目中添加 jar ...
- android通过toast实现悬浮通知效果,如图: 实现的功能: 自定义悬浮弹窗; 点击其他地方该布局不受影响;...
- 因为公司app的需求,需要加个自定义消息推送通知声音,因为不懂安卓的原生,所以之前被卡了很久,查了很多资料,终于搞...
- 在Demo中通过ObjectAimator实现的效果,使用一个View同样可以实现。 实现这个自定义View需要解...
- 今天是端午节,祝大家节日快乐 这篇文章着实酝酿了许久,一直懒得写。网上关于通知栏样式适配的文章很多,但还不够完美,...