I am developing an app which shows a heads up notification when an incoming or outgoing call is made (tested and working when not in a call). The feature is perfectly working on many devices(Xiomi, Huawei, Oppo devices). But in the latest Samsung devices, heads up notification is not shown. Instead, notification stays in the notification center and the user has to swipe down to see the notification. Does anyone else face a similar issue and have a solution?
Code snippets:
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);
}
In android - The Heads up notifications have a built in rate limit.
If the user swipes your heads up notification up (putting it back into the notification tray) or to the side (dismissing it), then that signals the system to prevent further heads up notifications for some period of time (for a minute by default).