pull/464/head
Robot 4 years ago
commit 48233e9892
  1. 40
      app/src/main/java/io/legado/app/App.kt

@ -6,7 +6,6 @@ import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Build import android.os.Build
import android.provider.Settings import android.provider.Settings
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDexApplication import androidx.multidex.MultiDexApplication
import com.jeremyliao.liveeventbus.LiveEventBus import com.jeremyliao.liveeventbus.LiveEventBus
@ -47,7 +46,7 @@ class App : MultiDexApplication() {
versionCode = it.versionCode versionCode = it.versionCode
versionName = it.versionName versionName = it.versionName
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannelId() createNotificationChannels()
applyDayNight() applyDayNight()
LiveEventBus LiveEventBus
.config() .config()
@ -87,41 +86,38 @@ class App : MultiDexApplication() {
/** /**
* 创建通知ID * 创建通知ID
*/ */
@RequiresApi(Build.VERSION_CODES.O) private fun createNotificationChannels() {
private fun createChannelId() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
(getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager)?.let { (getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager)?.let {
//用唯一的ID创建渠道对象
val downloadChannel = NotificationChannel( val downloadChannel = NotificationChannel(
channelIdDownload, channelIdDownload,
getString(R.string.action_download), getString(R.string.action_download),
NotificationManager.IMPORTANCE_LOW NotificationManager.IMPORTANCE_LOW
) ).apply {
//初始化channel enableLights(false)
downloadChannel.enableLights(false) enableVibration(false)
downloadChannel.enableVibration(false) setSound(null, null)
downloadChannel.setSound(null, null) }
//用唯一的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
) ).apply {
//初始化channel enableLights(false)
readAloudChannel.enableLights(false) enableVibration(false)
readAloudChannel.enableVibration(false) setSound(null, null)
readAloudChannel.setSound(null, null) }
//用唯一的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
) ).apply {
//初始化channel enableLights(false)
webChannel.enableLights(false) enableVibration(false)
webChannel.enableVibration(false) setSound(null, null)
webChannel.setSound(null, null) }
//向notification manager 提交channel //向notification manager 提交channel
it.createNotificationChannels(listOf(downloadChannel, readAloudChannel, webChannel)) it.createNotificationChannels(listOf(downloadChannel, readAloudChannel, webChannel))

Loading…
Cancel
Save