0

I'm developing and alarm like app that send notifications with fullscreenintents

The notifications themselves should be silent because the alarm sound will be looped and played apart from the notification sound.

But whatever I do, I can't change the sound or the vibration of the app

val fullScreenPendingIntent = PendingIntent.getActivity(context, 0,
        Intent(context, SecondActivity::class.java), FLAG_IMMUTABLE)

    val closeButtonPendingIntent = PendingIntent.getBroadcast(context, 0, Intent(context, CloseButton::class.java), FLAG_IMMUTABLE)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

        val name = "name"
        val descriptionText = "desc"
        val importance = NotificationManager.IMPORTANCE_HIGH
        val channel = NotificationChannel("abc", name, importance).apply {
            description = descriptionText
        }


        val notificationManager: NotificationManager =
            context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.createNotificationChannel(channel)

        channel.setSound(null, null)

        val builder = NotificationCompat.Builder(context, "abc")
            .setSmallIcon(R.drawable.ic_android_black_24dp)
            .setContentTitle("textTitle")
            .setContentText("textContent")
            .setVibrate(longArrayOf(1L, 2L, 3L))
            .setSound(null)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setCategory(NotificationCompat.CATEGORY_ALARM)
            .setFullScreenIntent(fullScreenPendingIntent, true)
            .addAction(1, "a", closeButtonPendingIntent)
            .setOnlyAlertOnce(false)
            .setOngoing(true)


        with(NotificationManagerCompat.from(context)) {
            notify(1, builder.build()).also { playNotification(context) }
        }
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Martim Gouveia
  • 81
  • 1
  • 2
  • 5
  • Probably you should call `setSound()` *before* calling `createNotificationChannel()`, as you cannot change a `Channel` once it has been created. You may also need to fully uninstall your app when testing the changes, as otherwise your channel will already exist. – CommonsWare Sep 05 '22 at 17:15
  • https://stackoverflow.com/a/52394243/14162959 – Crebain Sep 05 '22 at 20:48

1 Answers1

0

You just simple set builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI), it set a null value for notification sound uri. So, it's silent. And don't forget uninstall old version your app and reinstall it to apply changes.

baonq-2356
  • 61
  • 4