Allow background sound notification
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<application
|
||||
android:label="tasq"
|
||||
android:name="${applicationName}"
|
||||
android:name=".App"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
@@ -47,7 +47,7 @@
|
||||
android:value="2" />
|
||||
<meta-data
|
||||
android:name="com.google.firebase.messaging.default_notification_channel_id"
|
||||
android:value="tasq_high_importance_channel" />
|
||||
android:value="tasq_custom_sound_channel_2" />
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.tasq
|
||||
|
||||
import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.media.AudioAttributes
|
||||
import android.net.Uri
|
||||
|
||||
class App : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
createTasqChannel()
|
||||
}
|
||||
|
||||
private fun createTasqChannel() {
|
||||
val channelId = "tasq_custom_sound_channel"
|
||||
val name = "TasQ notifications"
|
||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||
val channel = NotificationChannel(channelId, name, importance)
|
||||
|
||||
val soundUri = Uri.parse("android.resource://$packageName/raw/tasq_notification")
|
||||
val audioAttributes = AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.build()
|
||||
|
||||
channel.setSound(soundUri, audioAttributes)
|
||||
|
||||
val nm = getSystemService(NotificationManager::class.java)
|
||||
nm?.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:keep="@raw/tasq_notification" />
|
||||
Binary file not shown.
Reference in New Issue
Block a user