gotify / android

An app for creating push notifications for new messages posted to gotify/server.
MIT License
947 stars 155 forks source link

Support different sounds and priority #18

Closed jvandenbroek closed 1 year ago

jvandenbroek commented 5 years ago

First of all, I'm really thankful someone finally created this self hosted solution :) Works great and seems pretty battery friendly, so I'm really happy with it as alternative for GCM.

Maybe you could extend it functionality a bit with being able to set different sounds per priority? I'd say priority 0 (or -1, don't know what the lowest is actually?) should never play any sound, that one shouldn't be to hard to implement I think? Next step (or maybe the same ;)) would be able to setup different sounds and colors per priority level.

And finally it would be really great if a sound field could be implemented on the server, which the client interprets. Just like pushover allows you to send different sounds, but I could imagine something simpler like settings sound1, sound2, sound3 etc in the client and just use that as value for the sound field.

jmattheis commented 5 years ago

Hey @jvandenbroek

I'm with you there, the priority isn't used anywhere and is currently only saved on server side. I would map the priority to the Android Importance like this:

Android Importance Gotify Priority
min 0
low 1 - 3
default 4 - 7
high 8 - 10

Each priority 0 - 10 (and 10+) could be a Notification Channel, with Android 8+ a custom sound can be added to each channel.

I don't really use sound on my phone as its mostly on vibrate only, so let's wait for more feedback about the custom sound thingy. (The importance mapping should still be done in the meantime)

schwma commented 5 years ago

I really like the idea of mapping Gotify message priorities to Android notification channels. So much so that I made a pull request #22 which makes the required changes.

Please let me know if I should make any further changes.

I have a question though @jmattheis. Why did you decide to have such a high granularity of message priorities in Gotify?

jmattheis commented 5 years ago

@schwma I've added priority really early on, back then all was kinda work in progress, I knew that something like priority should exist but badly I haven't really thought about it, so I just made it integer.

jvandenbroek commented 5 years ago

@schwma Great work, thanks! However unfortunately I'm only using Android 6, so I think notification channel sound won't work? For now it would be nice if just priority 0 disables sound and vibration, that would be very usable for me.

schwma commented 5 years ago

@jvandenbroek Hmmm, thats strange. The way I understood it, notification channel importances should be backwards compatible. I just tried it on an Android 6 device and all notification channels play sounds and vibrate, so they don't seem to be. I'll try to figure out whats happening when I find the time.

jvandenbroek commented 5 years ago

@schwma ah no I misunderstood, because @jmattheis said above for Android 8+, I didn't check this out myself. I (unfortunately) don't have an Android dev environment to build it myself, so haven't tested your PR.. Guess it should work for me as well then, great! :+1:

Edit: Ah should read better, he's talking about custom sounds, not channel notification in general, silly me :P

schwma commented 5 years ago

@jvandenbroek Honestly, I'm not sure it will work. I tried it with an Android 6 device that I have here and it didn't work. I'm not entirely sure why though.

jmattheis commented 5 years ago

@schwma @jvandenbroek NotificationCompact has this method

/**
 * Set the default notification options that will be used.
 * <p>
 * The value should be one or more of the following fields combined with
 * bitwise-or:
 * {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE},
 * {@link Notification#DEFAULT_LIGHTS}.
 * <p>
 * For all default values, use {@link Notification#DEFAULT_ALL}.
 */
public Builder setDefaults(int defaults) {/*...*/}

Currently DEFAULT_SOUND and DEFAULT_LIGHTS are set on the message notification, (DEFAULT_VIBRATE comes with DEFAULT_SOUND I guess). Without Notification channels there are no restrictions so it just uses these defaults.

schwma commented 5 years ago

@jmattheis But then how do you set no flags at all (or a flag for no sound/vibration/light)? I tried to remove the setDefault() calls entirely, but that didn't seem to change anything.

jmattheis commented 5 years ago

@schwma Hmm maybe it has some defaults (:, You can try .setDefaults(~Notification.DEFAULT_ALL)

nogweii commented 5 years ago

I would very much like custom sounds myself. It'd be even nicer if I could specify a default sound for an application in the server and have clients automatically download the sound.

sik0vny commented 5 years ago

I was also thinking about defining per-token sound defined in Gotify app. But evaryont has a good point, having a sounds uploaded on server would be great.

The ideal way would be:

  1. Save sounds on server, download them and use them in app (like the icons now)
  2. If user want to override a sound for certain token or all tokens - he can do that by choosing a sound from his SDcard
jmattheis commented 5 years ago

@evaryont @sik0vny With Android version 8 you can specify custom sounds. See here how to do it. It can be configured for each category listed in here.

Tho' it is not customizable for each application and must be customized on each device.

ktpx commented 5 years ago

Im currently using pushover, and like their server side sound support. Would be cool to see this on gotify, as in the prosess over moving over.

jceloria commented 4 years ago

I recently moved to a pretty rural area where satellite was the only option, I have several notifications that I have come to rely on around my house that I also use pushover for because of the custom sounds. Unfortunately, if its raining then my connection sucks, and I don't get the notifications... This is what ultimately lead me to this project, so a +1 for custom sounds.

newhinton commented 4 years ago

I have tried to implement this feature. But it seems this will not be an easy task, since the setLight() method which is used to set it to Color.CYAN is only obeyed once, and after that it is set as long as its corresponding NotificationChannel exists. I have not tried to find out if this holds true for sounds aswell.

See: https://stackoverflow.com/questions/53278255/notification-channel-is-it-possible-to-change-lightcolor-after-its-been-set/53288303#53288303 and https://stackoverflow.com/questions/51032697/allowing-the-user-to-set-notification-light-color-since-oreo-api-26

This means to support this, gotify needs to remove the priority based message channels and create app-based message channels (and recreate them when the user changes light (and possibly sounds)). This comes with its obvious downsides.

@jmattheis Is this something which should be done?

jmattheis commented 4 years ago

I think removing the channels for priorities will be a no-go. Priorities should still be supported. Maybe we could use the RingtoneManager to play the custom sound: https://stackoverflow.com/a/9622040/4244993

jmattheis commented 1 year ago

Closing in favor of https://github.com/gotify/android/issues/75

diamondburned commented 6 months ago

Closing in favor of #75

Sorry for commenting on an old issue, but #75 doesn't really discuss the custom sound feature. Could this issue be re-opened for that?

jmattheis commented 6 months ago

You can define a custom notification sound in the android notification settings:

image

Please open a new ticket if you have problems with that, so that not everyone in this thread is notified.