Skip to content

Commit

Permalink
fix notifications on android 31+
Browse files Browse the repository at this point in the history
  • Loading branch information
F43nd1r committed Jul 30, 2022
1 parent ad8a010 commit c9283f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.acra.interaction
import android.content.Context
import org.acra.config.CoreConfiguration
import org.acra.log.debug
import org.acra.log.warn
import org.acra.plugins.loadEnabled
import java.io.File
import java.util.concurrent.ExecutionException
Expand Down Expand Up @@ -49,6 +50,7 @@ class ReportInteractionExecutor(private val context: Context, private val config
sendReports = sendReports and future.get()
} catch (ignored: InterruptedException) {
} catch (e: ExecutionException) {
warn(e) { "Report interaction threw exception, will be ignored." }
//ReportInteraction crashed, so ignore it
break
}
Expand Down
1 change: 1 addition & 0 deletions acra-notification/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application>
<receiver
android:name="org.acra.receiver.NotificationBroadcastReceiver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,24 @@ class NotificationInteraction : HasConfigPlugin(NotificationConfiguration::class
return false
}

private val pendingIntentFlags = if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}

private fun getSendIntent(context: Context, config: CoreConfiguration, reportFile: File): PendingIntent {
val intent = Intent(context, NotificationBroadcastReceiver::class.java)
intent.action = INTENT_ACTION_SEND
intent.putExtra(LegacySenderService.EXTRA_ACRA_CONFIG, config)
intent.putExtra(EXTRA_REPORT_FILE, reportFile)
return PendingIntent.getBroadcast(context, ACTION_SEND, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getBroadcast(context, ACTION_SEND, intent, pendingIntentFlags)
}

private fun getDiscardIntent(context: Context): PendingIntent {
val intent = Intent(context, NotificationBroadcastReceiver::class.java)
intent.action = INTENT_ACTION_DISCARD
return PendingIntent.getBroadcast(context, ACTION_DISCARD, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getBroadcast(context, ACTION_DISCARD, intent, pendingIntentFlags)
}

private fun getSmallView(context: Context, notificationConfig: NotificationConfiguration, sendIntent: PendingIntent, discardIntent: PendingIntent): RemoteViews {
Expand Down
5 changes: 5 additions & 0 deletions web/docs/Interactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ import NotificationImage from '@site/static/img/captures/notification.png'

A notification is shown. A report will only be sent if the user agrees.

:::info
If the user has disabled this notification channel in the Android settings, no report will be sent!
This may be the default setting. It is your own responsibility to ask the user to allow these notifications.
:::

<AndroidCode>

```kotlin
Expand Down

0 comments on commit c9283f5

Please sign in to comment.