0xf104a / NextcloudServices

Android app to send notifications from Nextcloud without using GCM(Google cloud messaging)
GNU General Public License v3.0
63 stars 11 forks source link

Opening relevant app on notification click #10

Open penguin86 opened 3 years ago

penguin86 commented 3 years ago

Hello @Andrewerr, I'm wrapping my head around implementing a feature that opens the relevant app on notification click, and I'd like to know your opinion.

The simplest way would be to use the url in the notification as intent (like when you visit a youtube.com/something url and your device opens YouTube app), but this cannot work with Nextcloud, as every instance has a different base url.

So I completed a very basic implementation that opens the relevant app using its package name (see https://github.com/penguin86/NextcloudServices/commit/9214895d9d4b39090a4a852f99e08c83c1578260 ). This work for all the applications for which the app knows the package name (there is an app->package name mapping in nextcloud_package_names.xml and every new app developed needs to be added there). If the app is not installed, the notification link will be opened in browser. This is fine to me, but I didn't issue a pull request because this isn't a complete solution: it works fine opening the corresponding app, but it opens the default activity or, if the app is running, brings on top the currently open activity. I.e., for Talk, you may click on a notification by John and see the Jack's chat, because it was the last you interacted with.

Now I'm trying to open the right activity, but this is definitely more challenging. There isn't a generic solution working for all apps. I.e., Talk receives a GCM (now FCM) push message, retrieves the notification from notification API (as we do) and generates its own activity-opening intent. We could mock the message GCM sends to Talk and call it a day, but this wouldn't work with the F-Droid flavor, as the GCM code is present only on the Gplay flavor. A solution could be bringing into NextcloudServices the entire notification parsing and intent generation code from Talk ( https://github.com/nextcloud/talk-android/blob/master/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java etc...), but I think this is bad for a couple of reasons:

Anyway, what do you think? Should we implement a per-app solution or is it sufficient to genericly open the right app, at least for now?

0xf104a commented 3 years ago

Hello. So first of all approach with opening url is very app dependant. In fact it may work for some apps and fail to another, because it requires app developers to implement handling by url, so they can open only urls having pattern say */index.php/apps/news/*, but from their side it may lead to url collision(so app will try to open urls which are not nextcloud instances), so we should not expect that such a method of opening an activity would be available. As for approach with opening app by the name: it very good approach, but has some disadvantages: first of all as you have already pointed out: is is very hard to open right activity, but also there is another problem: if there is several apps providing handling for same types of notifications which one we should open?(e.g. there are few nextcloud news readers and so we will need to register them all and also there maybe situation when user for some reason have two of nextcloud news readers). And FCM has a different way of delivering notifications rather then this app: at first app itself subscribes to a FCM(via Google Play services), then when messag is delivered Play services call(probably using Parcel API) an app which parses it(in fact message can be anything: for example Telegram used FCM to deliver proxy lists ) and calls procdure of handling. So as we see there is no way to deliver notifcation in generic way(except UnfifiedPush which was mentioned in issue #11, but using it again requires an implementation by Nextcloud app developers). Thus lets take Talk app as an example. I have read their Manifest and found an activity which probably may handle a particular chat:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="vnd.android.cursor.item/vnd.com.nextcloud.talk2.chat" />
</intent-filter>

As it can be seen from this snippet Nextcloud Talk expects intent with specific mime-type which would porbably(have not checked it yet) will open right app. So in my opinion the best solution is as follows:

Such an implementation would be generic enough and so we can definetely implement processors for opening url and opening app now and then in future implement app-specific processors. Also I am not sure whether we really need those priorities, but it definetely safer having them :)

Gene-W commented 2 years ago

Hello, I've been trying several different settings to get notifications from Nextcloud Talk and then saw this conversation. I'm not very knowledgable in this area, so is this saying that notifications from Talk can't open in the Talk app just yet?

0xf104a commented 2 years ago

Hello @Gene-W. Yes opening app relevant to notification(e.g. Talk on spreed notifications) is not yet implemented. Currently app only opens web version of relevant app. In future I am going to implement this feature

Gene-W commented 2 years ago

Hello @Gene-W. Yes opening app relevant to notification(e.g. Talk on spreed notifications) is not yet implemented. Currently app only opens web version of relevant app. In future I am going to implement this feature

Excellent, thank you for clarifying. And thank you for your work on this project!

ahcheing commented 2 months ago

I hate to be that annoying user who bothers foss devs with pings of "any progress?" but since deck app dev seems reluctant to implement built-in notifications for his app and since I dont have the skills to understand what this means I'm not sure what else to do other then ask if there has been any updates to this feature.

This is a pretty important feature for the deck app. Right now If I get a notification from deck that I need to reach out to alice, I cant do anything with it, because I cant click on the notification to open the deck app and see that its a reminder to talk with her about bob.

0xf104a commented 2 months ago

@ahcheing Hello. Unfortunately I can not implement this solely by myself. It is possible for me to tell for example Deck that something happend(e.g. notification), though from other side @stefan-niedermann would need to write a code handling the notifications from my app