Workaround for notification icon on KitKat

This commit is contained in:
Davide Depau 2018-08-14 15:41:22 +02:00
parent 0584d2545a
commit c8254dedfe
Signed by: depau
GPG key ID: C7D999B6A55EFE86
2 changed files with 11 additions and 6 deletions

View file

@ -13,7 +13,7 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
android.defaultConfig.vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }
buildTypes { buildTypes {
release { release {

View file

@ -6,6 +6,7 @@ import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.support.v4.app.NotificationCompat
import eu.depau.ddroid.R import eu.depau.ddroid.R
import eu.depau.ddroid.utils.getFileName import eu.depau.ddroid.utils.getFileName
import eu.depau.ddroid.utils.toHRSize import eu.depau.ddroid.utils.toHRSize
@ -19,7 +20,7 @@ abstract class UsbWriteService(name: String) : IntentService(name) {
private var prevBytes = 0L private var prevBytes = 0L
private var notifyChanRegistered = false private var notifyChanRegistered = false
fun getNotificationBuilder(): Notification.Builder { fun getNotificationBuilder(): NotificationCompat.Builder {
if (!notifyChanRegistered) { if (!notifyChanRegistered) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channame = "USB write progress" val channame = "USB write progress"
@ -37,9 +38,9 @@ abstract class UsbWriteService(name: String) : IntentService(name) {
} }
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification.Builder(this, WRITE_PROGRESS_CHANNEL_ID) NotificationCompat.Builder(this, WRITE_PROGRESS_CHANNEL_ID)
else else
Notification.Builder(this) NotificationCompat.Builder(this)
} }
fun updateNotification(usbDevice: String, uri: Uri, bytes: Long, total: Long) { fun updateNotification(usbDevice: String, uri: Uri, bytes: Long, total: Long) {
@ -65,7 +66,9 @@ abstract class UsbWriteService(name: String) : IntentService(name) {
.setContentTitle("Write failed") .setContentTitle("Write failed")
.setContentText("The USB drive may have been unplugged while writing.") .setContentText("The USB drive may have been unplugged while writing.")
.setOngoing(false) .setOngoing(false)
.setSmallIcon(R.drawable.ic_usb_white_24dp)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
b.setSmallIcon(R.drawable.ic_usb_white_24dp)
notificationManager.notify(FOREGROUND_ID, b.build()) notificationManager.notify(FOREGROUND_ID, b.build())
} }
@ -87,9 +90,11 @@ abstract class UsbWriteService(name: String) : IntentService(name) {
b.setContentTitle("Writing image") b.setContentTitle("Writing image")
.setContentText("${uri.getFileName(this)} to $usbDevice") .setContentText("${uri.getFileName(this)} to $usbDevice")
.setOngoing(true) .setOngoing(true)
.setSmallIcon(R.drawable.ic_usb_white_24dp)
.setProgress(100, progr, indet) .setProgress(100, progr, indet)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
b.setSmallIcon(R.drawable.ic_usb_white_24dp)
if (subText != null) if (subText != null)
b.setSubText(subText) b.setSubText(subText)