Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

FCM data only notifications



  • Hi all,

    I'm trying to receive data only notifications from FCM into our app using the QtCloudMessaging APIs. So far we've managed to receive these when the app is in the foreground but when the app is in the background or not running at all the notifications doesn't reach our C++ implementation.

    As per documentation we added the onNewIntent function into our activity:

    public class NotificationActivity extends org.qtproject.qt5.android.bindings.QtActivity
    {
        /**/
        @Override
        public void onCreate(Bundle savedInstanceState) {
            Log.d("QTAPP", "onCreate");
            super.onCreate(savedInstanceState);
        }
    
        @Override
        protected void onNewIntent(Intent intent) {
            Log.d("QTAPP", "A message was sent to this app while it was in the background.");
            Intent message = new Intent(this, MessageForwardingService.class);
            message.setAction(MessageForwardingService.ACTION_REMOTE_INTENT);
            message.putExtras(intent);
            message.setData(intent.getData());
            startActivity(message);
        }
    

    Changed our AndroidManifest.xml accordingly so our Activity will be used instead of the default one (QtActivity).

    For debugging we added some log lines into the QtCloudMessaging lib:

    
    void QCloudMessagingFirebaseClient::OnMessage(const::firebase::messaging::Message &message)
    {
        qDebug() << "QCloudMessagingFirebaseClient::OnMessage" << parseMessage(message);
    

    When logcat is running and we're sending our data only notification to the app (when it is in the background), we observe the following output:

    30108 D QTAPP: QCloudMessagingFirebaseClient::OnMessage "{\"from\":\"\",\"message_id\":\"\",\"data\":{\"key\":value}}"
    

    Indicating that the QtCloudMessaging is setup properly. But none of our C++ hooks are executed and we're not sure what is going wrong here.

    I suspect the Qt event loop isn't started upon receiving the message but I cannot figure out why.

    Someone able to help us?



  • Did you have your own function public void onMessageReceived(RemoteMessage remoteMessage) in your Activity
    For me, the message would come into that function when I push notification from Firebase.



  • No, I don't have that. I assumed that the C++ bindings of FCM would take care of that. Isn't it that the case?



  • In my case, I think use that function is an easy case to get notification.
    You can try it if it fit your requirements


Log in to reply