首页 > 解决方案 > Kotlin:将 LongArray 定义为 Notification.Builder.setVibrate(LONG_ARRAY)

问题描述

我正在使用 Kotlin 并想为通知设置振动。该.setVibrate()功能需要一个LongArray,但我无法为它定义。

var Builder = NotificationCompat.Builder(this,R.string.channel_name.toString())
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle("my notification Title")
        .setContentText("somthing else for content")
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .setAutoCancel(true)
        .setVibrate(LONG_ARRAY)

我在网上搜索,但只是找到 java 的解决方案。谢谢你的帮助。

标签: androidkotlinandroid-notifications

解决方案


.setVibrate(longArrayOf(1L, 2L, 3L)) 

会工作得很好,或者

.setVibrate(listOf(1L, 2L, 3L).toLongArray())

如果你真的想要。


推荐阅读