android icon indicating copy to clipboard operation
android copied to clipboard

Android Notification Channel Support

Open eternal-flame-AD opened this issue 6 years ago • 8 comments

We can add Notification Channel support (create a channel for each application) so that we can toggle application notifications independently on the android client.

eternal-flame-AD avatar Jun 18 '19 01:06 eternal-flame-AD

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.

quthla avatar Aug 02 '19 11:08 quthla

I think the application list is already cached in the application and can be used directly.

eternal-flame-AD avatar Aug 02 '19 12:08 eternal-flame-AD

Maybe it could but what if I create an app in the panel, not open the app after and then send a message?

quthla avatar Aug 02 '19 12:08 quthla

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?

eternal-flame-AD avatar Aug 02 '19 13:08 eternal-flame-AD

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?

quthla avatar Aug 02 '19 13:08 quthla

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
        }
    }

jmattheis avatar Aug 02 '19 17:08 jmattheis

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?

quthla avatar Aug 02 '19 18:08 quthla

Yeah, we can probably move the creation of channels into the MessageActivity to prevent multiple calls for obtaining the applications.

jmattheis avatar Aug 02 '19 18:08 jmattheis

@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 avatar Jan 10 '23 18:01 quthla

@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.

cyb3rko avatar Jan 11 '23 13:01 cyb3rko

@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.

cyb3rko avatar Jan 12 '23 08:01 cyb3rko

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

cyb3rko avatar Feb 08 '23 18:02 cyb3rko