Karn / notify

Simplified notification construction and delivery for Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to set Importance of a notification ?

SyedAsimAliSE opened this issue · comments

hi , is there any way i can change the notification importance ? i want to disable the sound of the notification . thanks

Hey @SyedAsimAliSE,

Notification importance is modified using the Alerting scope. You can set the notification importance using the following block while constructing your notification:

// Define a new (notification) channel key for this alerting type.
// In the future you can use this key to send notifications using the same alerting settings. 
val channelKey = "low_priority_notifications"

Notify.with(this.context)
    // ...
    .alerting(channelKey) {
        // Set (notification) channel importance to one of the IMPORTANCE constants.
        channelImportance = Notify.IMPORTANCE_LOW
    }
    // ...

Let me know if you run into issues.

Marking this as resolved.

Hi, Karn thank you so much for the response, but i missed to respond you back in time because of the Github notification . i only get the email when you closed this.

i tried it with two API versions , 23 and 26. in api 26 it is working as expected [showing the notification after other notifications] but in api 23 it had no effect, notification is always at top and sound is not turned off . is there anything else i can do ?

snippet :

val channelKey = "low_priority_notifications"
                   Notify
                        .with(this@DetailsActivity)
                        .alerting(channelKey){
                            channelImportance = Notify.IMPORTANCE_LOW
                        }
                        .asBigPicture {
                            title = "LOREM"
                            text = "LOREM"
                            image = bitmap
                        }
                        .show()

thanks

That's strange, I've created a branch experimental/notification-priority which I think may address the issue you're seeing. Unfortunately, I don't have an API 23 device at my disposal and cannot validate the changes.

If possible can you try with this branch? You can use implementation io.karn:notify:aded694ad9 in your module's build.gradle.

it's also weird that Github isn't sending me any notifications for this issue :D , i will update you after giving it a try first in the morning .

You can hit the subscribe button to ensure that you receive updates for this issue.

Hey Karn !, it worked as expected on both the API's, no sound when setting it to LOW and sound when NORMAL :) . thank you

Perfect, I've merged the changes. You should be now able to use implementation io.karn:notify:1230a29734 from the develop branch.