Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with receiving messages #80

Closed
provokateurin opened this issue Jul 15, 2022 · 39 comments
Closed

Problems with receiving messages #80

provokateurin opened this issue Jul 15, 2022 · 39 comments

Comments

@provokateurin
Copy link
Member

Receiving messages works right after initialization.
When restarting the app and receiving a message after that it doesn't work anymore. In the logs I can see the Android code is definitely called.
When the app is in background or closed, receiving a message also doesn't work (same as above with receiving on the Android side).

Maybe these are actually the same problem, I suspect the callback is just never called for some reason.
I tried the embedded FOSS FCM and nfty distributors, both have the same problem and from the logs I collected I'm very confident this problem is distributor independent.

I will try to investigate it a little bit and see if adapting stuff from https://github.com/firebase/flutterfire/blob/master/packages/firebase_messaging/firebase_messaging/android/src/main/java/io/flutter/plugins/firebase/messaging/FlutterFirebaseMessagingBackgroundService.java helps.

@karmanyaahm
Copy link
Member

Hey👋

I'm really excited to see a Nextcloud w/ UP app. I will try to look at what might be going wrong today/tmrw.

(I'm sure @p1gp1g's android expertise will be helpful if they have time to look too)

@provokateurin
Copy link
Member Author

I'm pretty sure something like OneSignal/OneSignal-Flutter-SDK#464 is needed for this to work. Afaict most of that code is copied from https://github.com/firebase/flutterfire/tree/master/packages/firebase_messaging/firebase_messaging/android/src/main/java/io/flutter/plugins/firebase/messaging.

So how can we coordinate this? I can put some time into implementing this, but I don't want to do the work if someone else is already working on it. If you want to fix it then do it, because then I can continue working on other stuff for the notifications in the app.

@provokateurin
Copy link
Member Author

I did some small refactoring and now at least the notifications work on subsequent runs. Background still not working.

@provokateurin
Copy link
Member Author

FluffyChat also uses UP, so maybe I can check what they are doing, because I guess that works.

@p1gp1g
Copy link
Member

p1gp1g commented Jul 18, 2022

What tests did you do ? Because the example (and fluffychat) definitely work in background and/or closed ?

@provokateurin
Copy link
Member Author

What do you mean with tests? My implementation just doesn't work. I didn't try the examples yet, because as I said in the second comment I don't want to duplicate efforts if someone is already working on it. I will check the examples now.

@provokateurin
Copy link
Member Author

LOL example works in background. Then I'm pretty sure I know what is wrong. The documentation just doesn't help a lot. I'll make a PR towards it to fix it.

@p1gp1g
Copy link
Member

p1gp1g commented Jul 18, 2022

I though you did some tests with the example and you had trouble to receive message with the app in background or closed.

PR to improve our doc are very welcomed :)

@provokateurin
Copy link
Member Author

Somehow I now don't receive the messages at all already on the Android side (looking at the logs). Message definitely arrives at the distributor.

@provokateurin
Copy link
Member Author

I just always get GCM : broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=de.provokateurin.harbour (has extras) } in the logs. That it is cancelled seems to be the problem.

@p1gp1g
Copy link
Member

p1gp1g commented Jul 18, 2022

Are you trying to use foss_embedded_fcm_distributor ? If so, we should close this issue and continue there. And remind that the foss embedded fcm distrib is still in beta :)

@provokateurin
Copy link
Member Author

Yes I'm trying the foss distributor. I can temporarily switch to the non-foss, but I need to use the foss one to publish on f-droid. I don't think the non-foss will help though, because I have the same problem when using nfty. I'll try anyway.

@provokateurin
Copy link
Member Author

Tried the same with the non-foss distributor. I don't think any of this is related to the distributor that is used.

@p1gp1g
Copy link
Member

p1gp1g commented Jul 18, 2022

You should try with ntfy then. I don't know if the GCM message is related to your problem but it is definitely dependent on Google Services.

Do not forget to wipe data of your app sometime, there might be using introduced in development, not wiped after code changes.

I can give a look at your code if it can help. You must receive notifications in background :)

@provokateurin
Copy link
Member Author

ntfy also doesn't work in the background

@provokateurin
Copy link
Member Author

provokateurin commented Jul 18, 2022

at this point i kinda suspect another plugin is making problems

@provokateurin
Copy link
Member Author

i'll just add all the plugins with native android code to the example app and see if it breaks.

@provokateurin
Copy link
Member Author

adding the plugins didn't break it.

with nfty i get this log and nothing after that:

07-18 20:51:19.759  5631  5653 D NtfyUpDistributor: Sending MESSAGE to de.provokateurin.harbour (token=836ca154-e396-4785-8a36-02e99a793ed0): {"subject":"ppOeSO5z5ok6/44urMYGRue1ZbwgbnAGkGqIM4S0LpWRSpXCYmFEfvx6+qirYAuBvffos9h9paZXIxO0vbEG22f3ec/T1tY7ndZQh7D+Zqq81Kc/YI2diAzGffXX7Q9hpFlaF51rgHzzYP4lsQwFGkFdh+pUEBIgf9OydBiEokt+kWX3LzABIOECVL1jeR2vLiaf8chDbl/EBw0idGhvO2567pDMkU8URUAPCCvzR1gLLDuEKk06bqWFIaoVDfxnhYULntXsIkGGIXRDc01AF6Au6mGfga1RcAVsZ35rJiiicDjnkZrtN48vU6jGYbpYlXbRRkvOgh7Xxg8chAaENw==","signature":"Lj3+J6OtbGjRIRaQHisWMAZz3k7dTkWHD04bVZpeGZMf6X5vNGbK/tJvZKVjf2ZNdFZsCOEdnszQd+Km73dQxonC6ChMVfb8+Cgci3hEDnKR29LN4XG8R+ilL6fsSI74Pp2WWQAXVAC4eehWLATnuM925se4RvMP5cOoEQUUvDvTlM+heXONrYHRAkzmoCPp4CThD2wUkX2bdbhQnWtvLsxrkwObf8LdKu6WjKcza0LbabIvpg3vDhx7zSBwnUN82Q10OW0EN/iwiTb0aNtunIryAdBje5+mzj/D0NpHlykeC3I3WbmN41LQnuzJAzjOd5Ie8gOB0y5ngDyg0Wz5GA==","priority":"normal","type":"alert"} (752 bytes)}

@provokateurin
Copy link
Member Author

so i think the broadcast intent is never received. idk why this happens now and used to work before.

@p1gp1g
Copy link
Member

p1gp1g commented Jul 18, 2022

@provokateurin
Copy link
Member Author

I rebuilt the example app exactly following the docs and it just works. There has to be something weird about my app.

@provokateurin
Copy link
Member Author

I copied the android folder to my app and it doesn't work. So that part is fine. I really think it has to be one of the plugins

@provokateurin
Copy link
Member Author

removing all plugins from my app also doesn't fix it.

i'm kind of out of ideas what it could be tbh.

@p1gp1g
Copy link
Member

p1gp1g commented Jul 18, 2022

I don't know, I haven't seen your code. Maybe you could share it so I can check that. Did you do any change android side ?

@provokateurin
Copy link
Member Author

The code is in the MR linked at the top. I have some local changes. I'll try on last time and then you can take a look.

@provokateurin
Copy link
Member Author

I pushed the code. Hopefully you can find something. I just recreated the android folder from scratch and added my changes on top, but also no luck.

@provokateurin
Copy link
Member Author

You don't need to look at all the changes. packages/harbour/ is the app. All the other changes are related to forwarding push messages from Nextcloud and so on.

@provokateurin
Copy link
Member Author

Can you set a breakpoint around there https://github.com/UnifiedPush/android-connector/blob/main/connector/src/main/java/org/unifiedpush/android/connector/MessagingReceiver.kt#L19 ? And/or check your shared pref

How can I do that? I don't even know how to include the connector from local sources.

@provokateurin
Copy link
Member Author

sorry for being so annoying, this is probably the worst bug i ever had because it doesn't make any sense 🙈

@p1gp1g
Copy link
Member

p1gp1g commented Jul 19, 2022

No problem, I'll try your code to check that soon ! :)

@provokateurin
Copy link
Member Author

i tried adding the android-connector from local sources, but just can't get it working :(

@provokateurin
Copy link
Member Author

my time of developing native android apps and fiddeling with java and kotlin is just too long ago. i need help from someone with more expertise in that field

@provokateurin
Copy link
Member Author

@p1gp1g did you have a chance to look at my code? i tried some other stuff, but nothing helped at all

@provokateurin
Copy link
Member Author

So I gradually add the code again and I got it working now. Really no clue what was wrong. I'll push my code later when I got it all working.

@provokateurin
Copy link
Member Author

It works pretty well now that it's reliable :D

@provokateurin
Copy link
Member Author

wow it's broken again. what i noticed is that i can close the app in release mode and the notifications still arrive as long as i don't stop the flutter run command. in the app settings i can see the app is not running in the background as it should:
Screenshot_20220723_150342
when i now open the app again and close it, i receive the notifications and also can press the force stop button. so is suspect this is something with the broadcast receiver getting killed for some reason.

@provokateurin
Copy link
Member Author

so i think flutter run just kills the app completely instead of only closing the visible window. that would explain why the app isn't even running in the background. that would mean there is no issue with UP at all, just bad DX from flutter.

@karmanyaahm
Copy link
Member

when i now open the app again and close it, i receive the notifications and also can press the force stop button. so is suspect this is something with the broadcast receiver getting killed for some reason.
that would mean there is no issue with UP at all, just bad DX from flutter.

That's great to hear!

We should document this somewhere. I'll test this with other apps and create an FAQ section on the Flutter page on the website if this keeps on happening (weird that I never noticed it, but I guess when testing I leave the app open longer than I keep flutter run running usually)

@provokateurin
Copy link
Member Author

i've fully integrated the notifications in my app now. no more issues so far other than the one i discovered. expect the feature to land in the app very soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants