Home > Net >  How to disable notification sound with keeping heads up notification?
How to disable notification sound with keeping heads up notification?

Time:09-22

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

CodePudding user response:

channel.setSound(null, null);

will disable sound for notification

CodePudding user response:

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

Thanks for DeePanShu.

  • Related