From 35a1ce62cd82071e5fbce94f1dd5a7ef169fcc89 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 8 Jun 2019 23:11:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/App.kt | 68 +++++++++++++------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 41e8dffaf..3d689582a 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -89,41 +89,43 @@ class App : Application() { */ @RequiresApi(Build.VERSION_CODES.O) private fun createChannelId() { - val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - //用唯一的ID创建渠道对象 - val downloadChannel = NotificationChannel( - channelIdDownload, - getString(R.string.download_offline), - NotificationManager.IMPORTANCE_LOW - ) - //初始化channel - downloadChannel.enableLights(false) - downloadChannel.enableVibration(false) - downloadChannel.setSound(null, null) + val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager + notificationManager?.let { + //用唯一的ID创建渠道对象 + val downloadChannel = NotificationChannel( + channelIdDownload, + getString(R.string.download_offline), + NotificationManager.IMPORTANCE_LOW + ) + //初始化channel + downloadChannel.enableLights(false) + downloadChannel.enableVibration(false) + downloadChannel.setSound(null, null) - //用唯一的ID创建渠道对象 - val readAloudChannel = NotificationChannel( - channelIdReadAloud, - getString(R.string.read_aloud), - NotificationManager.IMPORTANCE_LOW - ) - //初始化channel - readAloudChannel.enableLights(false) - readAloudChannel.enableVibration(false) - readAloudChannel.setSound(null, null) + //用唯一的ID创建渠道对象 + val readAloudChannel = NotificationChannel( + channelIdReadAloud, + getString(R.string.read_aloud), + NotificationManager.IMPORTANCE_LOW + ) + //初始化channel + readAloudChannel.enableLights(false) + readAloudChannel.enableVibration(false) + readAloudChannel.setSound(null, null) - //用唯一的ID创建渠道对象 - val webChannel = NotificationChannel( - channelIdWeb, - getString(R.string.web_service), - NotificationManager.IMPORTANCE_LOW - ) - //初始化channel - webChannel.enableLights(false) - webChannel.enableVibration(false) - webChannel.setSound(null, null) + //用唯一的ID创建渠道对象 + val webChannel = NotificationChannel( + channelIdWeb, + getString(R.string.web_service), + NotificationManager.IMPORTANCE_LOW + ) + //初始化channel + webChannel.enableLights(false) + webChannel.enableVibration(false) + webChannel.setSound(null, null) - //向notification manager 提交channel - notificationManager.createNotificationChannels(Arrays.asList(downloadChannel, readAloudChannel, webChannel)) + //向notification manager 提交channel + it.createNotificationChannels(Arrays.asList(downloadChannel, readAloudChannel, webChannel)) + } } }