11package org.schabi.newpipe.error
22
33import android.app.Activity
4- import android.app.NotificationManager
54import android.app.PendingIntent
65import android.content.Context
76import android.content.Intent
@@ -10,7 +9,7 @@ import android.os.Build
109import android.view.View
1110import android.widget.Toast
1211import androidx.core.app.NotificationCompat
13- import androidx.core.content.ContextCompat
12+ import androidx.core.app.NotificationManagerCompat
1413import androidx.fragment.app.Fragment
1514import com.google.android.material.snackbar.Snackbar
1615import org.schabi.newpipe.R
@@ -105,13 +104,6 @@ class ErrorUtil {
105104 */
106105 @JvmStatic
107106 fun createNotification (context : Context , errorInfo : ErrorInfo ) {
108- val notificationManager =
109- ContextCompat .getSystemService(context, NotificationManager ::class .java)
110- if (notificationManager == null ) {
111- // this should never happen, but just in case open error activity
112- openActivity(context, errorInfo)
113- }
114-
115107 var pendingIntentFlags = PendingIntent .FLAG_UPDATE_CURRENT
116108 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
117109 pendingIntentFlags = pendingIntentFlags or PendingIntent .FLAG_IMMUTABLE
@@ -122,7 +114,13 @@ class ErrorUtil {
122114 context,
123115 context.getString(R .string.error_report_channel_id)
124116 )
125- .setSmallIcon(R .drawable.ic_bug_report)
117+ .setSmallIcon(
118+ // the vector drawable icon causes crashes on KitKat devices
119+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP )
120+ R .drawable.ic_bug_report
121+ else
122+ android.R .drawable.stat_notify_error
123+ )
126124 .setContentTitle(context.getString(R .string.error_report_notification_title))
127125 .setContentText(context.getString(errorInfo.messageStringId))
128126 .setAutoCancel(true )
@@ -135,7 +133,8 @@ class ErrorUtil {
135133 )
136134 )
137135
138- notificationManager!! .notify(ERROR_REPORT_NOTIFICATION_ID , notificationBuilder.build())
136+ NotificationManagerCompat .from(context)
137+ .notify(ERROR_REPORT_NOTIFICATION_ID , notificationBuilder.build())
139138
140139 // since the notification is silent, also show a toast, otherwise the user is confused
141140 Toast .makeText(context, R .string.error_report_notification_toast, Toast .LENGTH_SHORT )
0 commit comments