【发布时间】:2019-10-18 05:05:18
【问题描述】:
我正在开发一个应用程序,它会在来电或去电时显示提醒通知(在未通话时经过测试并正常工作)。该功能在许多设备(小米、华为、Oppo 设备)上都能完美运行。但在最新的三星设备中,没有显示抬头通知。相反,通知保留在通知中心,用户必须向下滑动才能看到通知。有没有其他人面临类似的问题并有解决方案?
代码 sn-ps:
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);
}
【问题讨论】:
标签: android android-notifications samsung-mobile heads-up-notifications