Merge pull request #7977 from Stypox/error-notification-kitkat
Fix error notification on KitKat
This commit is contained in:
commit
1ecb0ca081
|
@ -1,7 +1,6 @@
|
||||||
package org.schabi.newpipe.error
|
package org.schabi.newpipe.error
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.NotificationManager
|
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
@ -10,7 +9,7 @@ import android.os.Build
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
|
@ -105,13 +104,6 @@ class ErrorUtil {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun createNotification(context: Context, errorInfo: ErrorInfo) {
|
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
|
var pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
pendingIntentFlags = pendingIntentFlags or PendingIntent.FLAG_IMMUTABLE
|
pendingIntentFlags = pendingIntentFlags or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
@ -122,7 +114,13 @@ class ErrorUtil {
|
||||||
context,
|
context,
|
||||||
context.getString(R.string.error_report_channel_id)
|
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))
|
.setContentTitle(context.getString(R.string.error_report_notification_title))
|
||||||
.setContentText(context.getString(errorInfo.messageStringId))
|
.setContentText(context.getString(errorInfo.messageStringId))
|
||||||
.setAutoCancel(true)
|
.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
|
// 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)
|
Toast.makeText(context, R.string.error_report_notification_toast, Toast.LENGTH_SHORT)
|
||||||
|
|
Loading…
Reference in New Issue