@@ -2,9 +2,11 @@ package org.schabi.newpipe.error
22
33import android.app.Activity
44import android.app.NotificationManager
5+ import android.app.PendingIntent
56import android.content.Context
67import android.content.Intent
78import android.graphics.Color
9+ import android.os.Build
810import android.view.View
911import androidx.core.app.NotificationCompat
1012import androidx.core.content.ContextCompat
@@ -28,10 +30,7 @@ class ErrorUtil {
2830 */
2931 @JvmStatic
3032 fun openActivity (context : Context , errorInfo : ErrorInfo ) {
31- val intent = Intent (context, ErrorActivity ::class .java)
32- intent.putExtra(ErrorActivity .ERROR_INFO , errorInfo)
33- intent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
34- context.startActivity(intent)
33+ context.startActivity(getErrorActivityIntent(context, errorInfo))
3534 }
3635
3736 @JvmStatic
@@ -68,18 +67,39 @@ class ErrorUtil {
6867 openActivity(context, errorInfo)
6968 }
7069
70+ var pendingIntentFlags = PendingIntent .FLAG_UPDATE_CURRENT
71+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
72+ pendingIntentFlags = pendingIntentFlags or PendingIntent .FLAG_IMMUTABLE
73+ }
74+
7175 val notificationBuilder: NotificationCompat .Builder =
7276 NotificationCompat .Builder (
7377 context,
7478 context.getString(R .string.error_report_channel_id)
7579 )
7680 .setSmallIcon(R .drawable.ic_bug_report)
77- .setContentTitle(context.getString(R .string.error_report_title ))
81+ .setContentTitle(context.getString(R .string.error_report_notification_title ))
7882 .setContentText(context.getString(errorInfo.messageStringId))
83+ .setAutoCancel(true )
84+ .setContentIntent(
85+ PendingIntent .getActivity(
86+ context,
87+ 0 ,
88+ getErrorActivityIntent(context, errorInfo),
89+ pendingIntentFlags
90+ )
91+ )
7992
8093 notificationManager!! .notify(ERROR_REPORT_NOTIFICATION_ID , notificationBuilder.build())
8194 }
8295
96+ private fun getErrorActivityIntent (context : Context , errorInfo : ErrorInfo ): Intent {
97+ val intent = Intent (context, ErrorActivity ::class .java)
98+ intent.putExtra(ErrorActivity .ERROR_INFO , errorInfo)
99+ intent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
100+ return intent
101+ }
102+
83103 private fun showSnackbar (context : Context , rootView : View ? , errorInfo : ErrorInfo ) {
84104 if (rootView == null ) {
85105 // fallback to showing a notification if no root view is available
0 commit comments