From a051f3a7d6e1946eb8a5624aedbdea43d475370f Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 5 Nov 2020 19:12:39 +0800 Subject: [PATCH 1/2] =?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 | 33 ++++++++++++-------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index a578bab15..782acb2b9 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -90,38 +90,35 @@ class App : MultiDexApplication() { @RequiresApi(Build.VERSION_CODES.O) private fun createChannelId() { (getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager)?.let { - //用唯一的ID创建渠道对象 val downloadChannel = NotificationChannel( channelIdDownload, getString(R.string.action_download), NotificationManager.IMPORTANCE_LOW - ) - //初始化channel - downloadChannel.enableLights(false) - downloadChannel.enableVibration(false) - downloadChannel.setSound(null, null) + ).apply { + enableLights(false) + enableVibration(false) + 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) + ).apply { + enableLights(false) + enableVibration(false) + 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) + ).apply { + enableLights(false) + enableVibration(false) + setSound(null, null) + } //向notification manager 提交channel it.createNotificationChannels(listOf(downloadChannel, readAloudChannel, webChannel)) From e8710813236c926f414f7ae31609d16228a5c6bf Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 5 Nov 2020 19:23:01 +0800 Subject: [PATCH 2/2] =?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 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 782acb2b9..a49704169 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -6,7 +6,6 @@ import android.content.Context import android.content.res.Configuration import android.os.Build import android.provider.Settings -import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatDelegate import androidx.multidex.MultiDexApplication import com.jeremyliao.liveeventbus.LiveEventBus @@ -47,7 +46,7 @@ class App : MultiDexApplication() { versionCode = it.versionCode versionName = it.versionName } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannelId() + createNotificationChannels() applyDayNight() LiveEventBus .config() @@ -87,8 +86,8 @@ class App : MultiDexApplication() { /** * 创建通知ID */ - @RequiresApi(Build.VERSION_CODES.O) - private fun createChannelId() { + private fun createNotificationChannels() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return (getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager)?.let { val downloadChannel = NotificationChannel( channelIdDownload,