android
android copied to clipboard
Android Notification Channel Support
We can add Notification Channel support (create a channel for each application) so that we can toggle application notifications independently on the android client.
I had a look at implementing this but I think it'd require the server to send the app name with the message so the appropriate channel can be created.
I think the application list is already cached in the application and can be used directly.
Maybe it could but what if I create an app in the panel, not open the app after and then send a message?
Yeah that might be a problem, but I don't think it is really worth it to induce an API change just to support this. Maybe we can have a fallback channel created for all applications that are currently unknown?
That could work but are you sure the app list cache can be easily retrieved from the webservice class? Is it even initialized when only the service is running and not the app itself?
The message already contains an application id, that's all what we need to create a temporary notification channel for this application if it is not yet exist.
The NotificationChannel should've an ID like this:String.format("gotify_application_%d", applicationId). When the WebSocket receives a message we do something like this, to ensure that an channel exist. The temp channel name should be overridden in https://github.com/gotify/android/blob/master/app/src/main/java/com/github/gotify/NotificationSupport.java
@RequiresApi(Build.VERSION_CODES.O)
private void createNotificationChannelIfNotExists(int appId) {
NotificationManager manager = getSystemService(NotificationManager.class);
if(manager.getNotificationChannel("gotify_application_" + appId) == null) {
String tempChannelName = "Uninitialized: Start app to update " + appId
// create new channel
}
}
Yeah that's not the issue but how exactly shall the app name be retrieved from the cache you referred too? Do you mean ApplicationHolder?
Yeah, we can probably move the creation of channels into the MessageActivity to prevent multiple calls for obtaining the applications.
@cyb3rko this is a longstanding issue. There's a PR but unfortunately it's stalled. As you've probably got some great insight into the code now after you rewrote it in Kotlin, is this maybe something you'd want to take care of when you've got some time and your PR was merged?
https://github.com/gotify/android/pull/212
@quthla Hi, As you've already mentioned, first of all I would wait for the merge of the Kotlin migration, as this is a major step forwards. Once that's done, I'll try to find some time between
- many exams coming soon
- working while studying
- and some other projects I'm working on.
When there's some time, I'll first have to take a look at Notification channels, as I have never worked with them before. Combined with that I would take a look at what you and newhinton already built.
And if I finally reach that point, I'll try to implement this feature while rewriting your drafts to Kotlin.
@quthla I forgot to mention that after merging the Kotlin PR we first have to fix notifications and websocket reconnection because we've upgraded to Android 13 SDKs.
Ok, I think the restructuring (ViewBinding, Kotlin, Design updates, etc...) can be considered pretty stable now as only one issue appeared so far which could easily be fixed (https://github.com/gotify/android/issues/274).
I'll surely find some time next week to take a look at #212 and try to follow the ideas and problems @jmattheis and @newhinton discussed there and why the PR failed in the end. I'm confident that we can recycle of lot of code that was produced there (but still it was written in Java, so no copy paste).
@quthla