QtFirebaseExample icon indicating copy to clipboard operation
QtFirebaseExample copied to clipboard

Notification not received with app in background

Open Trikos opened this issue 5 years ago • 15 comments

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

Trikos avatar Mar 24 '20 13:03 Trikos

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.

larpon avatar Mar 24 '20 15:03 larpon

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

Trikos avatar Mar 24 '20 15:03 Trikos

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

Trikos avatar Mar 24 '20 17:03 Trikos

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 :smiley:
  • 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 :smiley:
  • 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 :wink:

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.

larpon avatar Mar 25 '20 15:03 larpon

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 😃

Trikos avatar Mar 25 '20 15:03 Trikos

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 :slightly_smiling_face: (AdMob is often the primary reason people use QtFirebase :slightly_smiling_face: )

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

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

larpon avatar Mar 25 '20 15:03 larpon

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

Trikos avatar Mar 25 '20 15:03 Trikos

I can safely delete it from manifest without problems right?

I think so, yes :+1:

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

larpon avatar Mar 25 '20 15:03 larpon

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

Trikos avatar Mar 25 '20 19:03 Trikos

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

larpon avatar Mar 26 '20 10:03 larpon

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 avatar May 27 '20 12:05 robin-hood-git

This seem to try and fix that exact problem? https://github.com/firebase/quickstart-cpp/blob/e0cef3cafaa5e8b0a50cd4125ab3a30e0aa91170/messaging/testapp/src/android/java/com/google/firebase/example/TestappNativeActivity.java#L31-L60

larpon avatar May 28 '20 09:05 larpon

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.

robin-hood-git avatar May 28 '20 14:05 robin-hood-git

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

larpon avatar May 29 '20 08:05 larpon

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

attisan avatar Sep 10 '20 14:09 attisan