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 7e10d5608..e62aad1df 100644
--- a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt
+++ b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt
@@ -2,9 +2,11 @@ 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
import android.graphics.Color
+import android.os.Build
import android.view.View
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
@@ -28,10 +30,7 @@ class ErrorUtil {
*/
@JvmStatic
fun openActivity(context: Context, errorInfo: ErrorInfo) {
- val intent = Intent(context, ErrorActivity::class.java)
- intent.putExtra(ErrorActivity.ERROR_INFO, errorInfo)
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- context.startActivity(intent)
+ context.startActivity(getErrorActivityIntent(context, errorInfo))
}
@JvmStatic
@@ -68,18 +67,39 @@ class ErrorUtil {
openActivity(context, errorInfo)
}
+ var pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ pendingIntentFlags = pendingIntentFlags or PendingIntent.FLAG_IMMUTABLE
+ }
+
val notificationBuilder: NotificationCompat.Builder =
NotificationCompat.Builder(
context,
context.getString(R.string.error_report_channel_id)
)
.setSmallIcon(R.drawable.ic_bug_report)
- .setContentTitle(context.getString(R.string.error_report_title))
+ .setContentTitle(context.getString(R.string.error_report_notification_title))
.setContentText(context.getString(errorInfo.messageStringId))
+ .setAutoCancel(true)
+ .setContentIntent(
+ PendingIntent.getActivity(
+ context,
+ 0,
+ getErrorActivityIntent(context, errorInfo),
+ pendingIntentFlags
+ )
+ )
notificationManager!!.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
}
+ private fun getErrorActivityIntent(context: Context, errorInfo: ErrorInfo): Intent {
+ val intent = Intent(context, ErrorActivity::class.java)
+ intent.putExtra(ErrorActivity.ERROR_INFO, errorInfo)
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ return intent
+ }
+
private fun showSnackbar(context: Context, rootView: View?, errorInfo: ErrorInfo) {
if (rootView == null) {
// fallback to showing a notification if no root view is available
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2824c9efb..f47322b79 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -246,6 +246,7 @@
Do you want to restore defaults?
Give permission to display over other apps
+ NewPipe encountered an error, tap to report
Sorry, that should not have happened.
Guru Meditation.
Report this error via e-mail