Cordova-plugin-firebase: (Android): Click on Notification is not opening the app

Created on 16 Sep 2016  路  16Comments  路  Source: arnesson/cordova-plugin-firebase

Android / Smartphone.

I can receive notifications, which display nicely in the notification area, but when I click on one, I would expect that the main app is launched. But it is not. Is there any particular reason for it?

I see that it should be supported: User taps the notification and the app opens

Most helpful comment

Oh my.... I just found my mistake after so much time lost...

I was using before this plugin cordova-plugin-fcm and I hardcoded in my REST client the payload... Now they advise there to use "click_action":"FCM_PLUGIN_ACTIVITY" and I just realized that actually, it filters out, somehow the activity... Removing this line solve the issue...

Sorry for all the trouble and thank you for the assistance

All 16 comments

what cordova version? also add the log output from the device please

Cordova 6.3.1, Android plugin: 5.2.2
Built is on an android device, version 5.0.1, API 21

More to the strange behavior:

  • App started, notification received: when app is put in background and then notification is clicked, the app restarts as expected
  • App in background, notification received: happens nothing but this log: W/FirebaseMessaging: Icon resource fcm_push_icon not found. Notification will use app icon.
  • App not started, notification received: it happens a little more in the logs, even so the application itself does not show up:
09-19 22:22:01.779 32399-32399/com.xxxxxx D/ResourcesManager: creating new AssetManager and set to /data/app/com.xxxxxx-2/base.apk
09-19 22:22:01.899 32399-32399/com.xxxxxx D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
09-19 22:22:01.919 32399-32399/com.xxxxxx D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
09-19 22:22:01.949 32399-32399/com.xxxxxx I/FA: App measurement is starting up, version: 9452
09-19 22:22:01.959 32399-32399/com.xxxxxx I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
09-19 22:22:01.999 32399-32399/com.xxxxxx I/FirebaseInitProvider: FirebaseApp initialization successful
09-19 22:22:02.029 32399-32446/com.xxxxxx W/FirebaseMessaging: Icon resource fcm_push_icon not found. Notification will use app icon.

Interestingly enough, I can reproduce this exact scenario in the Emulator (Nexus 6). I'm wondering just why this seems to happen only to me.

@Krisa have you tried with the latest version from the repo? I re-wrote the android part of the open notification and @robertarnesson accepted it. Would be nice if you could test it and give us some feedback.

@BugsBunnyBR just tested and unfortunately no, this is still not working (i.e. same behaviour than the one I described previously

Maybe an hint on the issue... This plugin works https://github.com/fechanique/cordova-plugin-fcm. When the app is off, I receive the notification and after clicking, the app is opened immediately. However, unlike cordova-plugin-firebase, I don't receive any notification when the app is on...

On cordova-plugin-fcm, when I tap the notification this starts with this:

09-25 11:38:45.035 14392-14392/com.pmi.fastrack D/FCMPlugin: ==> FCMPluginActivity onCreate
09-25 11:38:45.035 14392-14392/com.pmi.fastrack D/FCMPlugin: ==> USER TAPPED NOTFICATION

But on cordova-plugin-firebase, it does nothing.

What version of android are you testing? I just removed all my node_modules, platforms and plugins folders and installed all stuff again. I can open the app tapping in the notification in when the app is open or in background or even killed by the app switch.
Tested in an Nexus 5 with Android 6.

My real device is a sgs4 android 5.0.1, API 21. But I've tested on an emulator, nexus 6, API 24, same issue. Not sure where the difference lies honestly ...

Just tested on emulators for Android 4.4 and 5.0. The app is being open as expected. Try to setup a repo with the problem you have and I will take a look.

OK, I have zipped the whole cordova project and simplified to the minimum (I've just removed the google-services.json): https://drive.google.com/file/d/0BzWpk0dob93BVGVwLTlmZGVDcE0/view

I am able to send notifications to your project and open them normally... I had to make some changes from what you send to make it work with a new FCM project... but changed nothing in the plugin part or in your index.js.

# added my google-services.json to the root folder
# changed the id in config.xml to the one in my FCM project
cordova platform rm android
cordova platform add android
cordova plugin rm cordova-plugin-firebase
cordova plugin add https://github.com/arnesson/cordova-plugin-firebase --save
cordova build android
cordova run android

The cordova-plugin-firebase was the latest from the repo, but needed to make it update some strings in the android strings.xml

Are you sure your main package (the id in config.xml) is the same from FCM project ?

Ok :/

I guess that before cordova build android, you need to start android studio so that it fetches all the Firebase modules?

if I don't, I get following log (same for messaging, crash and config):

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
   > Could not find any matches for com.google.firebase:firebase-core:+ as no versions of com.google.firebase:firebase-core are available.
     Searched in the following locations:
         https://repo1.maven.org/maven2/com/google/firebase/firebase-core/maven-metadata.xml
         https://repo1.maven.org/maven2/com/google/firebase/firebase-core/
         https://jcenter.bintray.com/com/google/firebase/firebase-core/maven-metadata.xml
         https://jcenter.bintray.com/com/google/firebase/firebase-core/
         file:/usr/local/Cellar/android-sdk/24.4.1_1/extras/android/m2repository/com/google/firebase/firebase-core/maven-metadata.xml
         file:/usr/local/Cellar/android-sdk/24.4.1_1/extras/android/m2repository/com/google/firebase/firebase-core/
         file:/usr/local/Cellar/android-sdk/24.4.1_1/extras/google/m2repository/com/google/firebase/firebase-core/maven-metadata.xml
         file:/usr/local/Cellar/android-sdk/24.4.1_1/extras/google/m2repository/com/google/firebase/firebase-core/
     Required by:
         :android:unspecified

But apart from that, yes, I do the same steps, and it fails... I receive the notification on my device, but nothing happens.

EDIT: yes, the id is correct (the one I provided is not the right one but both match correctly in my real config)

the cordova build command will download most* of the dependencies for you.
I know that if you open your project in Android Studio it will try to update the version of some gradle dependencies and the build will fail when trying to build from cordova... I don`t know if this is the case to you. And to fix that you will have to remove the android platorm and add again.

  • Some dependencies like google play services and google repository need to be downloaded from Android Studio SDK manager ( you can open the SDK manager with the command android if it is in your PATH).

Yes, I'm not very familiar with it, but at least I could get it working this way. Just wanted to ensure that it may not be the cause.

The only thing I can think, is that the dependencies I'm downloading are of a different version than yours?

I have tried to put debug logs in all @override methods and somehow, nothing is shown when I click on a notification... So we could assume that the code is simply never called?

Going forward with the investigation, I'm trying to compare this rep with cordova-plugin-fcm. One thing which I find suspicious is that I cannot find anything which implements "Activity" like here: https://github.com/fechanique/cordova-plugin-fcm/blob/master/src/android/FCMPluginActivity.java#L21
Quoting the comment:

this activity will be started if the user touches a notification that we own. We send it's data off to the push plugin for processing. If needed, we boot up the main activity to kickstart the application.

Now, if this is not in this plugin, how is it implemented? And could it explain the difference?

Oh my.... I just found my mistake after so much time lost...

I was using before this plugin cordova-plugin-fcm and I hardcoded in my REST client the payload... Now they advise there to use "click_action":"FCM_PLUGIN_ACTIVITY" and I just realized that actually, it filters out, somehow the activity... Removing this line solve the issue...

Sorry for all the trouble and thank you for the assistance

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eilian92 picture eilian92  路  4Comments

matthitachi picture matthitachi  路  5Comments

arunkatariaoodles picture arunkatariaoodles  路  4Comments

Zrnik picture Zrnik  路  3Comments

stephan-nordnes-eriksen picture stephan-nordnes-eriksen  路  5Comments