0

I want

I'm noob for android.

My app displays heads up notification. Now, my app always ringing when it listen notification regardless silent mode ON/OFF.

I want to do next things.

Disable notification sound with keeping heads up notification in silent mode.


Thanks for your help.

Problem

My app ringing when silent mode.

code

MainActivity.kt
val channel = NotificationChannel(
    notificationType.channelId,
    notificationType.channelName,
    NotificationManager.IMPORTANCE_HIGH
).apply {
    setSound(uri, attribute)
    enableVibration(true)
    vibrationPattern = createVibrate()
    lightColor = Color.BLUE
}
channel.lockscreenVisibNotification.VISIBILITY_PUBLIC
manager.createNotificationChannel(channel)
PushNotificationListenerService.kt
val notificationBuilder = NotificationComBuilder(this, receivedChannelId)
    .setContentTitle(title)
    .setContentText(text)
    .setSmallIcon(R.drawable.ic_menu_logo)
    .setContentIntent(pendingIntent)
    .setPriority(PRIORITY_MAX)
    .setCategory(CATEGORY_CALL)
    .setSound(defaultSoundUri)
    .setVibrate(createVibrate())
    .setAutoCancel(true)
    .setLights(Color.BLUE, 5000, 10)

things I tried

  • Switch setSound settings corresponding to silent mode. (This is not working.)
  • Try to set notificationBuilder.setSilent(true). (Heads up notification deleted.)
  • Try to change NotificationManager.IMPORTANCE_HIGH to IMPORTANCE_LOW. (Heads up notification deleted.)

Else info

versions
kotlin_version = "1.4.32"
navigation_version = "2.3.5"
activity_version = "1.2.3"
fragment_version = "1.3.6"

compileSdkVersion 29
buildToolsVersion "30.0.3"

minSdkVersion 21
targetSdkVersion 29

kotlinOptions {
    jvmTarget = '1.8'
}
devise version
devise name: AQUOS sense4 basic
devise android version: 10

devise notification setting
all ON

msickpaler
  • 89
  • 1
  • 7
  • 1
    This will be helpful you: https://stackoverflow.com/a/54785422/10954249 and use audio manager to check whether sound settings is in ring or silent. – DeePanShu Sep 21 '21 at 05:37
  • 1
    Does this answer your question? [Android : Notification sound disable](https://stackoverflow.com/questions/7655164/android-notification-sound-disable) – Deepak Kumar Sep 22 '21 at 04:04

2 Answers2

0
channel.setSound(null, null);

will disable sound for notification

Saurabh Dhage
  • 1,478
  • 5
  • 17
  • 31
0

I solved this problem by https://stackoverflow.com/a/54785422/14019506

Thanks for DeePanShu.

msickpaler
  • 89
  • 1
  • 7