我正在开发一个应用程序,该应用程序在打入或打出电话时显示抬头通知(在未通话时进行测试并可以正常工作)。 该功能可以在许多设备(小米,华为,Oppo设备)上完美运行。但是在最新的三星设备中,不会显示抬头通知。相反,通知保留在通知中心,用户必须向下滑动才能看到通知。 还有其他人面临类似的问题并有解决方案吗?
代码段:
private var manager: NotificationManager? = null
val manger: NotificationManager
get() {
if(manager==null) {
manager = if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
applicationContext.getSystemService(NotificationManager::class.java)
} else {
applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
}
}
return manager!!
}
private fun createNotificationChannel() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val mChannel = NotificationChannel(ID,NAME,NotificationManager.IMPORTANCE_HIGH)
mChannel.setShowBadge(true)
mChannel.enableVibration(true)
mChannel.lockscreenVisibility=Notification.VISIBILITY_PUBLIC
manger.createNotificationChannel(mChannel)
}
}
public static NotificationCompat.Builder showNotification(Context context, String notificationChannel, String Message, String title) {
Bitmap picture = Utils.decodeResource(context.getResources(), R.drawable.notifi, 64, 64);
return new NotificationCompat.Builder(context, notificationChannel)
.setLargeIcon(picture)
.setSmallIcon(R.drawable.splash_logo)
.setColor(context.getResources().getColor(R.color.colorPrimaryDark))
.setContentTitle(title)
.setContentText(Message)
.setAutoCancel(true)
.setOngoing(true)
.setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(Notification.CATEGORY_CALL)
.setVibrate(new long[0])
.setTimeoutAfter(10000);
}