diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt index 3fd743c69..e4dd2e16d 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt @@ -1,7 +1,6 @@ package org.schabi.newpipe.error import android.app.Activity -import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent @@ -10,7 +9,7 @@ import android.os.Build import android.view.View import android.widget.Toast import androidx.core.app.NotificationCompat -import androidx.core.content.ContextCompat +import androidx.core.app.NotificationManagerCompat import androidx.fragment.app.Fragment import com.google.android.material.snackbar.Snackbar import org.schabi.newpipe.R @@ -105,13 +104,6 @@ class ErrorUtil { */ @JvmStatic fun createNotification(context: Context, errorInfo: ErrorInfo) { - val notificationManager = - ContextCompat.getSystemService(context, NotificationManager::class.java) - if (notificationManager == null) { - // this should never happen, but just in case open error activity - openActivity(context, errorInfo) - } - var pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { pendingIntentFlags = pendingIntentFlags or PendingIntent.FLAG_IMMUTABLE @@ -122,7 +114,13 @@ class ErrorUtil { context, context.getString(R.string.error_report_channel_id) ) - .setSmallIcon(R.drawable.ic_bug_report) + .setSmallIcon( + // the vector drawable icon causes crashes on KitKat devices + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + R.drawable.ic_bug_report + else + android.R.drawable.stat_notify_error + ) .setContentTitle(context.getString(R.string.error_report_notification_title)) .setContentText(context.getString(errorInfo.messageStringId)) .setAutoCancel(true) @@ -135,7 +133,8 @@ class ErrorUtil { ) ) - notificationManager!!.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build()) + NotificationManagerCompat.from(context) + .notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build()) // since the notification is silent, also show a toast, otherwise the user is confused Toast.makeText(context, R.string.error_report_notification_toast, Toast.LENGTH_SHORT)