Android發送個普通自定義常駐通知

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) } }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章