|
|
@ -89,41 +89,43 @@ class App : Application() { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@RequiresApi(Build.VERSION_CODES.O) |
|
|
|
@RequiresApi(Build.VERSION_CODES.O) |
|
|
|
private fun createChannelId() { |
|
|
|
private fun createChannelId() { |
|
|
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager |
|
|
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager |
|
|
|
//用唯一的ID创建渠道对象 |
|
|
|
notificationManager?.let { |
|
|
|
val downloadChannel = NotificationChannel( |
|
|
|
//用唯一的ID创建渠道对象 |
|
|
|
channelIdDownload, |
|
|
|
val downloadChannel = NotificationChannel( |
|
|
|
getString(R.string.download_offline), |
|
|
|
channelIdDownload, |
|
|
|
NotificationManager.IMPORTANCE_LOW |
|
|
|
getString(R.string.download_offline), |
|
|
|
) |
|
|
|
NotificationManager.IMPORTANCE_LOW |
|
|
|
//初始化channel |
|
|
|
) |
|
|
|
downloadChannel.enableLights(false) |
|
|
|
//初始化channel |
|
|
|
downloadChannel.enableVibration(false) |
|
|
|
downloadChannel.enableLights(false) |
|
|
|
downloadChannel.setSound(null, null) |
|
|
|
downloadChannel.enableVibration(false) |
|
|
|
|
|
|
|
downloadChannel.setSound(null, null) |
|
|
|
|
|
|
|
|
|
|
|
//用唯一的ID创建渠道对象 |
|
|
|
//用唯一的ID创建渠道对象 |
|
|
|
val readAloudChannel = NotificationChannel( |
|
|
|
val readAloudChannel = NotificationChannel( |
|
|
|
channelIdReadAloud, |
|
|
|
channelIdReadAloud, |
|
|
|
getString(R.string.read_aloud), |
|
|
|
getString(R.string.read_aloud), |
|
|
|
NotificationManager.IMPORTANCE_LOW |
|
|
|
NotificationManager.IMPORTANCE_LOW |
|
|
|
) |
|
|
|
) |
|
|
|
//初始化channel |
|
|
|
//初始化channel |
|
|
|
readAloudChannel.enableLights(false) |
|
|
|
readAloudChannel.enableLights(false) |
|
|
|
readAloudChannel.enableVibration(false) |
|
|
|
readAloudChannel.enableVibration(false) |
|
|
|
readAloudChannel.setSound(null, null) |
|
|
|
readAloudChannel.setSound(null, null) |
|
|
|
|
|
|
|
|
|
|
|
//用唯一的ID创建渠道对象 |
|
|
|
//用唯一的ID创建渠道对象 |
|
|
|
val webChannel = NotificationChannel( |
|
|
|
val webChannel = NotificationChannel( |
|
|
|
channelIdWeb, |
|
|
|
channelIdWeb, |
|
|
|
getString(R.string.web_service), |
|
|
|
getString(R.string.web_service), |
|
|
|
NotificationManager.IMPORTANCE_LOW |
|
|
|
NotificationManager.IMPORTANCE_LOW |
|
|
|
) |
|
|
|
) |
|
|
|
//初始化channel |
|
|
|
//初始化channel |
|
|
|
webChannel.enableLights(false) |
|
|
|
webChannel.enableLights(false) |
|
|
|
webChannel.enableVibration(false) |
|
|
|
webChannel.enableVibration(false) |
|
|
|
webChannel.setSound(null, null) |
|
|
|
webChannel.setSound(null, null) |
|
|
|
|
|
|
|
|
|
|
|
//向notification manager 提交channel |
|
|
|
//向notification manager 提交channel |
|
|
|
notificationManager.createNotificationChannels(Arrays.asList(downloadChannel, readAloudChannel, webChannel)) |
|
|
|
it.createNotificationChannels(Arrays.asList(downloadChannel, readAloudChannel, webChannel)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|