Support native alert suppression on Android 14 and 15
This commit is contained in:
@@ -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>
|
||||
|
||||
+39
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user