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

Notification not received with app in background #25

Open
Trikos opened this issue Mar 24, 2020 · 15 comments
Open

Notification not received with app in background #25

Trikos opened this issue Mar 24, 2020 · 15 comments

Comments

@Trikos
Copy link

Trikos commented Mar 24, 2020

I check the Java code and I think it miss some part of code in order to receive the notification when the app is closed.
Also it needs the relative part in the manifest?
I was able to install everything and when sending notification from my own server my own google-services the notification appear in the console, but when the app is in background it didnt receive the push notification

@larpon
Copy link
Owner

larpon commented Mar 24, 2020

I get messages with QtFirebaseExample (also when the app is killed or have been suspended for a long time) - so I'm assuming it's a setup problem. The messages can take a little while to arrive. No extra Java should be necessary than what is in this section of Main.java.

Also it needs the relative part in the manifest?

I'm not sure I understand this question?

Others are reporting similar issues
You could try adding a service as I suggest but it really shouldn't be necessary.

@Trikos
Copy link
Author

Trikos commented Mar 24, 2020

Trying to do everything from zero. Let you know :D

@Trikos
Copy link
Author

Trikos commented Mar 24, 2020

I tried to use a service but is not that simple. I don't know how implement it in the Main.java in order to run the service and send me the notification when it arrives. I set it into the manifest (https://imgur.com/a/4N8wUKG), then I imported the package necessary for qt (https://imgur.com/oX4BQa1) and then I'm lost on what to do next.
Anyway I reset the whole project, inserted my google-services and made some test.
the notification it never arrives when the app is in background or foreground. Only when I open it up the notification appeared in the console. I wait 2 mins but nothing.
A friend of mine said that I miss a broadcast receiver???
@larpon Do you mind to reupload the project with a service?
I really appreciate all the work (instead of OneSignal / Felgo) but without receiving the push notification when the app is closed I can't using it and I want to use it because is free and well made.
As I said I just download and setup your project and build it with my google-services.json but the notification don't arrived.
I post my manifest and Main.java so you can check it if you want. Really appreciate your help
(The editor cant let me set the code tag in the right way sorry)
Manifest.txt
Main.txt

@larpon
Copy link
Owner

larpon commented Mar 25, 2020

Hi @Trikos ,

I think it's something else wrong in your setup - as I already stated: a service shouldn't be necessary :)

I reset the whole project, inserted my google-services and made some test

Cool - now use this as a base for your own project if possible - then use QtFirebaseExample as a reference project.

Follow the SETUP for Android to every detail - this is what all other users are doing.

Double check that no app id's are left over anywhere from QtFirebaseExample.
I'd use grep to identify where these could "hide", on my machine output looks like this (from the root project folder):

App/qml/pages/Messaging.qml
16:            var url = "http://blackgrain.dk/php/qtfirebase/"

App/platforms/android/google-services.json
13:          "package_name": "com.blackgrain.android.firebasetest"

App/platforms/android/AndroidManifest.xml
2:<manifest package="com.blackgrain.android.firebasetest" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0.0-armv7" android:versionCode="1" android:installLocation="auto">
10:        <meta-data android:name="com.google.android.gms.ads.ca-app-pub-6606648560678905~6485875670" android:value="com.blackgrain.android.firebasetest"/>
16:        <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="com.blackgrain.android.firebasetest.Main" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@style/AppTheme" android:launchMode="singleTop">

App/platforms/ios/GoogleService-Info.plist
20:     <string>com.blackgrain.ios.firebasetest</string>

App/platforms/android/build.gradle
89:        applicationId "com.blackgrain.android.firebasetest" // Used by Firebase auto-config (the google-services.json from Firebase console)

App/platforms/android/src/com/blackgrain/android/firebasetest/Main.java
1:package com.blackgrain.android.firebasetest;

Other things to consider:

  • Make sure you replace com.blackgrain.android.firebasetest and com.google.android.gms.ads.ca-app-pub-XX with your own ids.
  • Remember that Java expects directories to match your id e.g: com.blackgrain.android.firebasetest.Main is in com/blackgrain/android/firebasetest/Main.java (note how they match).
  • Wipe your builds now and then to make sure qmake isn't using old/cached data.
  • Triple check that you have Google Play services installed.
  • Triple check that you're not blocking ads or other network routes on your phone or WiFi.
  • Triple check that you're allowing your app to actually receive notifications (permissions, volume, flight mode, custom apps that block XYZ feature).
  • this URL is not a service I provide - it's only there for me to test QtFirebase for this project. (And it currently doesn't work)
  • Make sure both QtFirebase and QtFirebaseExample is on master branch - they always match.
  • This is a spare time pet project - I can't and won't go through your project code, sorry 😃
  • QtFirebaseExample is provided as a working example, a reference, of a working setup. Qt projects can literally be setup in a million different ways - we haven't got resources to provide support for individual cases.
  • We're always open to suggestions on how to improve the documentation or setup in general 😃
  • If you still think something is wrong with QtFirebase try and see how the code QtFirebase is wrapping is working, things change quickly at Google

Do you mind to reupload the project with a service?

In the politest manner possible: Yes, I do mind - see all of the above 😉

I know it's possible to get running because I know of several live apps in the app stores that uses QtFirebase - also with messaging.

@Trikos
Copy link
Author

Trikos commented Mar 25, 2020

Well I think I miss a piece that you write here and wasnt explained in the doc.

Make sure you replace com.blackgrain.android.firebasetest and com.google.android.gms.ads.ca-app-pub-XX with your own ids.

I dont know what id should be this last one so Im gonna go further with it and dont worry. You are super polite and super helpful. I'm gonna go through all the steps again.
Also can you indicate me the apps that are using QtFirebase so Im gonna check them out? And maybe ask some question to the developers 😃

@larpon
Copy link
Owner

larpon commented Mar 25, 2020

Well I think I miss a piece that you write here and wasnt explained in the doc.

Noted! Thanks! I'll try to make it more clear.

Ah the com.google.android.gms.ads.ca-app-pub-... is probably for AdMob 🙂 (AdMob is often the primary reason people use QtFirebase 🙂 )

Also can you indicate me the apps that are using QtFirebase so Im gonna check them out?

I would if I could remember them 😬. Have you checked out the "In the wild" section? (Hammer Bees & Dead Ascend is my games but they don't use Messaging)

@Trikos
Copy link
Author

Trikos commented Mar 25, 2020

Ok, so I don't need the com.google.android.gms.ads.ca-app-pub- because I'm not using AdMobs so I can safely delete it from manifest without problems right?

I would if I could remember them 😬. Have you checked out the "In the wild" section? (Hammer Bees & Dead Ascend is my games and they don't use Messaging)

Now I'm checking out those apps. Thank you

@larpon
Copy link
Owner

larpon commented Mar 25, 2020

I can safely delete it from manifest without problems right?

I think so, yes 👍

Also Google's own Firebase C++ example might be of interest - best of luck!

@Trikos
Copy link
Author

Trikos commented Mar 25, 2020

I noticed something that maybe can be useful.
I have a test app for push notification that work with our server and I saw that inside the app notifcation that are categories and when I disable these categories the notification didnt arrive. Looking inside the app based on this example, once is built, inside the notifcations I didnt see the Categories and I think this could be the problem at 90%. Do you have categories in your example app. Because I think that without category I will not be able to receive notifcations. If you can check I really appreciate that.
This is what I meant
photo_2020-03-25_20-01-06
photo_2020-03-25_20-01-07
PicoIslands that use this library has a category and notifications arrive (foreground/background), mine example hasnt and notifications doesnt arrive (foreground/background).
Thank you again Larpon

@larpon
Copy link
Owner

larpon commented Mar 26, 2020

No I don't have any categories, I have no idea what they are and how they're used. The notifications still arrive. We use topics though.

You can read more about FCM concepts here:
https://firebase.google.com/docs/cloud-messaging/concept-options

@robin-hood-git
Copy link

Hello,
I have the same problem.

What works:
If the app is in the foreground, the received messages are displayed in the app under "Console". Very good!
If the app is in the background, messages are received and displayed in the message bar of the device. Also very good. However, if I click on the message in the message bar, it is not displayed in the app under "Console".
When I click on this message, the function onNewIntent(Intent intent) from Main.java is called. After that I get to the function OnMessage from qtfirebasemessaging.cpp.

What does not work:
Unfortunately, the object message.notification is false (0x0), so no message is displayed. Only message.notification_opened is true, but this does not help me.

How can I now display the message?
This should normally be possible, or am I wrong?

@robin-hood-git
Copy link

At first I thought with the code piece that I had finally made it, but it still doesn't work.

I've now added the line following, but when I now click on the received message from the message bar of my device, the app crashes.

The code changing:
message.setData(intent.getData());

Since in the example shown, the extend class is different (with them "QtActivity" and in this example "NativeActivity"), I changed it afterwards, but when I do so, the app crashes always I open it.

@larpon
Copy link
Owner

larpon commented May 29, 2020

Hmm... can you post a backtrace or something similar of the crash?

@attisan
Copy link

attisan commented Sep 10, 2020

could be a nullpointer when
Bundle extras = intent.getExtras();
isn't checked before access

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

4 participants