diff --git a/app/src/main/java/com/aurora/store/AuroraApplication.kt b/app/src/main/java/com/aurora/store/AuroraApplication.kt index f4196dcbd..89bf57e69 100644 --- a/app/src/main/java/com/aurora/store/AuroraApplication.kt +++ b/app/src/main/java/com/aurora/store/AuroraApplication.kt @@ -19,8 +19,12 @@ package com.aurora.store +import android.app.NotificationChannel +import android.app.NotificationManager +import android.os.Build import androidx.appcompat.app.AppCompatDelegate import androidx.multidex.MultiDexApplication +import com.aurora.Constants import com.aurora.store.data.downloader.DownloadManager import com.aurora.store.data.providers.NetworkProvider import com.aurora.store.data.receiver.PackageManagerReceiver @@ -28,6 +32,7 @@ import com.aurora.store.data.service.NotificationService import com.aurora.store.util.CommonUtil import com.aurora.store.util.PackageUtil import com.tonyodev.fetch2.Fetch +import java.util.ArrayList import nl.komponents.kovenant.android.startKovenant import nl.komponents.kovenant.android.stopKovenant @@ -45,6 +50,9 @@ class AuroraApplication : MultiDexApplication() { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) + //Create Notification Channels : General & Alert + createNotificationChannel() + NotificationService.startService(this) fetch = DownloadManager.with(this).fetch @@ -79,4 +87,33 @@ class AuroraApplication : MultiDexApplication() { .unbind() super.onLowMemory() } -} \ No newline at end of file + + private fun createNotificationChannel() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager + val channels = ArrayList() + channels.add( + NotificationChannel( + Constants.NOTIFICATION_CHANNEL_ALERT, + getString(R.string.notification_channel_alert), + NotificationManager.IMPORTANCE_HIGH + ) + ) + channels.add( + NotificationChannel( + Constants.NOTIFICATION_CHANNEL_GENERAL, + getString(R.string.notification_channel_general), + NotificationManager.IMPORTANCE_MIN + ) + ) + channels.add( + NotificationChannel( + Constants.NOTIFICATION_CHANNEL_UPDATER_SERVICE, + getString(R.string.notification_channel_updater_service), + NotificationManager.IMPORTANCE_MIN + ) + ) + notificationManager.createNotificationChannels(channels) + } + } +} diff --git a/app/src/main/java/com/aurora/store/data/service/NotificationService.kt b/app/src/main/java/com/aurora/store/data/service/NotificationService.kt index 3fa6fcf3f..fda9f1884 100644 --- a/app/src/main/java/com/aurora/store/data/service/NotificationService.kt +++ b/app/src/main/java/com/aurora/store/data/service/NotificationService.kt @@ -92,9 +92,6 @@ class NotificationService : Service() { notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager - //Create Notification Channels : General & Alert - createNotificationChannel() - fetch = DownloadManager.with(this).fetch fetchListener = object : AbstractFetchGroupListener() { @@ -147,34 +144,6 @@ class NotificationService : Service() { fetch.addListener(fetchListener) } - private fun createNotificationChannel() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val channels = ArrayList() - channels.add( - NotificationChannel( - Constants.NOTIFICATION_CHANNEL_ALERT, - getString(R.string.notification_channel_alert), - NotificationManager.IMPORTANCE_HIGH - ) - ) - channels.add( - NotificationChannel( - Constants.NOTIFICATION_CHANNEL_GENERAL, - getString(R.string.notification_channel_general), - NotificationManager.IMPORTANCE_MIN - ) - ) - channels.add( - NotificationChannel( - Constants.NOTIFICATION_CHANNEL_UPDATER_SERVICE, - getString(R.string.notification_channel_updater_service), - NotificationManager.IMPORTANCE_MIN - ) - ) - notificationManager.createNotificationChannels(channels) - } - } - private fun showNotification(groupId: Int, download: Download, fetchGroup: FetchGroup) { val status = download.status @@ -466,4 +435,4 @@ class NotificationService : Service() { EventBus.getDefault().unregister(this); super.onDestroy() } -} \ No newline at end of file +}