问题
I am adding the new HeadsUp notification to my Android app to be shown as an incoming call which will ring for 30 or 40 seconds. The default HeadsUp notification just ring for 10 seconds and then stops. I searched for a while to find a way to make the notification ring for 30 or 40 seconds. It seems that there is nothing could make me control the Notification Ringing duration.
Answering my question This was my updated notification initialization code to answer my question:
Notification myNotification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(remote_picture)
.setContentIntent(resultPendingIntent)
.setContentTitle("Vehicle Health Monitor")
.setVibrate(new long[20])
.setCategory(Notification.CATEGORY_CALL)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentText(msg)
.setAutoCancel(false)
.build();
mNotificationManager.notify(NOTIFICATION_ID, myNotification);
So mainly, the solution was to set notification category to Notification.CATEGORY_CALL
来源:https://stackoverflow.com/questions/37850240/controlling-android-notification-duration-for-headsup