Android 安卓推送在几秒钟后解散
我正在尝试创建传入呼叫推送通知。当发生呼叫事件时,前台服务将启动并发出通知。我为它和通知创建了一个通道。代码如下: 频道设置:Android 安卓推送在几秒钟后解散,android,foreground-service,android-push-notification,Android,Foreground Service,Android Push Notification,我正在尝试创建传入呼叫推送通知。当发生呼叫事件时,前台服务将启动并发出通知。我为它和通知创建了一个通道。代码如下: 频道设置: private fun createCallChannelChannel(): NotificationChannel { val attributes = AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .build()
private fun createCallChannelChannel(): NotificationChannel {
val attributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build()
val importance = NotificationManager.IMPORTANCE_HIGH
return NotificationChannel(CALL_CHANNEL_ID, CALL_CHANNEL_NAME, importance).apply {
description = CALL_CHANNEL_DESCRIPTION
setSound(
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE),
attributes
)
enableLights(true)
enableVibration(true)
}
}
private fun buildIncomingCallNotification(payload: VoIpCallResponse): Notification {
val remoteView = RemoteViews(packageName, R.layout.notification_call_view)
remoteView.setOnClickPendingIntent(R.id.declineBtn, getDeclinePendingIntent())
remoteView.setOnClickPendingIntent(R.id.acceptBtn, getAcceptPendingIntent(payload))
return NotificationCompat.Builder(this, CALL_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(remoteView)
.setAutoCancel(false)
.build()
}
通知设置:
private fun createCallChannelChannel(): NotificationChannel {
val attributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build()
val importance = NotificationManager.IMPORTANCE_HIGH
return NotificationChannel(CALL_CHANNEL_ID, CALL_CHANNEL_NAME, importance).apply {
description = CALL_CHANNEL_DESCRIPTION
setSound(
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE),
attributes
)
enableLights(true)
enableVibration(true)
}
}
private fun buildIncomingCallNotification(payload: VoIpCallResponse): Notification {
val remoteView = RemoteViews(packageName, R.layout.notification_call_view)
remoteView.setOnClickPendingIntent(R.id.declineBtn, getDeclinePendingIntent())
remoteView.setOnClickPendingIntent(R.id.acceptBtn, getAcceptPendingIntent(payload))
return NotificationCompat.Builder(this, CALL_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(remoteView)
.setAutoCancel(false)
.build()
}
它起作用了。正在显示通知。但问题是通知会在几秒钟后最小化到通知栏。目标是在用户拒绝/接受呼叫或结束呼叫事件发生之前,防止通知最小化。比如WhatsApp。来电通知会无限期地显示在屏幕顶部。我怎样才能做同样的?我的频道的重要性是NotificationManager.importance\u HIGH,通知优先级是NotificationCompat.priority\u MAX我找到了这个页面,它已经运行了 当然,使用foregroundService
val incomingCallNotification = notificationBuilder.build()
我已经找到了这个页面,它已经工作了 当然,使用foregroundService
val incomingCallNotification = notificationBuilder.build()