aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Heckel <pheckel@datto.com>2022-11-28 06:00:41 -0500
committerPhilipp Heckel <pheckel@datto.com>2022-11-28 06:00:41 -0500
commitb3a0a10b605a7b49b2d7f4c51d1cec54050899fe (patch)
treecdaf9b8fdc2d030e93e076ee5e8db5586f88847d
parentfa27fe903604217325fdb6fc9cc67221b88fb8c7 (diff)
downloadponypush-b3a0a10b605a7b49b2d7f4c51d1cec54050899fe.tar.gz
ponypush-b3a0a10b605a7b49b2d7f4c51d1cec54050899fe.tar.bz2
ponypush-b3a0a10b605a7b49b2d7f4c51d1cec54050899fe.zip
Constant ring
-rw-r--r--app/src/main/AndroidManifest.xml2
-rw-r--r--app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt59
2 files changed, 60 insertions, 1 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4cbdf60..35689fd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -134,6 +134,8 @@
android:exported="false">
</receiver>
+ <receiver android:name=".msg.NotificationService$AlarmReceiver"/>
+
<!-- Firebase messaging (note that this is empty in the F-Droid flavor) -->
<service
android:name=".firebase.FirebaseService"
diff --git a/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt b/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt
index 8f5a7aa..f49d426 100644
--- a/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt
+++ b/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt
@@ -5,6 +5,9 @@ import android.content.ActivityNotFoundException
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
+import android.media.AudioAttributes
+import android.media.AudioManager
+import android.media.MediaPlayer
import android.media.RingtoneManager
import android.net.Uri
import android.os.Build
@@ -79,8 +82,61 @@ class NotificationService(val context: Context) {
maybeAddCancelAction(builder, notification)
maybeAddUserActions(builder, notification)
+
+
maybeCreateNotificationChannel(notification.priority)
- notificationManager.notify(notification.notificationId, builder.build())
+ val systemNotification = builder.build()
+ if (channelId == CHANNEL_ID_MAX) {
+ //systemNotification.flags = systemNotification.flags or android.app.Notification.FLAG_INSISTENT
+ }
+ notificationManager.notify(notification.notificationId, systemNotification)
+
+ if (channelId == CHANNEL_ID_MAX) {
+ Log.d(TAG, "Setting alarm")
+ /*val calendar = Calendar.getInstance()
+ val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as? AlarmManager
+ val intent = Intent(context, AlarmReceiver::class.java)
+ val pendingIntent = PendingIntent.getBroadcast(context, 1111, intent, PendingIntent.FLAG_IMMUTABLE)
+ // when using setAlarmClock() it displays a notification until alarm rings and when pressed it takes us to mainActivity
+
+ alarmManager?.set(
+ AlarmManager.RTC_WAKEUP,
+ calendar.timeInMillis, pendingIntent
+ )*/
+
+ val alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
+ val mMediaPlayer = MediaPlayer()
+
+ mMediaPlayer.setDataSource(context, alert)
+ val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
+ if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
+ mMediaPlayer.setAudioAttributes(AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM).build())
+ mMediaPlayer.isLooping = true;
+ mMediaPlayer.prepare();
+ mMediaPlayer.start();
+ mMediaPlayer.stop()
+ }
+
+ }
+ }
+
+ class AlarmReceiver : BroadcastReceiver() {
+ override fun onReceive(context: Context?, intent: Intent?) {
+ Log.d(TAG, "AlarmReceiver.onReceive ${intent}")
+ val context = context ?: return
+
+ val alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
+ val mMediaPlayer = MediaPlayer()
+
+ mMediaPlayer.setDataSource(context, alert)
+ val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
+ if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
+ mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
+ mMediaPlayer.setLooping(true);
+ mMediaPlayer.prepare();
+ mMediaPlayer.start();
+ }
+ }
}
private fun maybeSetSound(builder: NotificationCompat.Builder, update: Boolean) {
@@ -333,6 +389,7 @@ class NotificationService(val context: Context) {
val channel = NotificationChannel(CHANNEL_ID_MAX, context.getString(R.string.channel_notifications_max_name), NotificationManager.IMPORTANCE_HIGH) // IMPORTANCE_MAX does not exist
channel.enableLights(true)
channel.enableVibration(true)
+ channel.setBypassDnd(true)
channel.vibrationPattern = longArrayOf(
pause, 100, pause, 100, pause, 100,
pause, 2000,