Controlling Android Notification Duration for HeadsUp

柔情痞子 提交于 2019-12-13 02:24:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!