Support native alert suppression on Android 14 and 15

This commit is contained in:
ajp_anton
2026-08-18 11:34:34 +00:00
parent dbe6335978
commit 243bf62e67
3 changed files with 83 additions and 14 deletions
+17 -1
View File
@@ -1 +1,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"><uses-permission android:name="android.permission.POST_NOTIFICATIONS"/><application android:theme="@style/Theme.AppCompat.DayNight"><activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application></manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application android:theme="@style/Theme.AppCompat.DayNight">
<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BackgroundPostReceiver" android:exported="true">
<intent-filter>
<action android:name="se.ajpanton.notificationsmaster.helper.POST_TEXT" />
</intent-filter>
</receiver>
</application>
</manifest>
@@ -0,0 +1,39 @@
package se.ajpanton.notificationsmaster.helper
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.media.AudioAttributes
import android.media.RingtoneManager
/** Posts an alerting test notification without bringing the helper activity forward. */
class BackgroundPostReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action != ACTION) return
val manager = context.getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(
NotificationChannel(CHANNEL, "Test", NotificationManager.IMPORTANCE_HIGH).apply {
setSound(
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),
AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build(),
)
enableVibration(true)
vibrationPattern = longArrayOf(0, 200)
},
)
manager.notify(ID, Notification.Builder(context, CHANNEL)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("Helper")
.setContentText("Text message")
.build())
}
companion object {
const val ACTION = "se.ajpanton.notificationsmaster.helper.POST_TEXT"
private const val CHANNEL = "test"
private const val ID = 1
}
}