chemerisuk / cordova-plugin-firebase-messaging

Cordova plugin for Firebase Cloud Messaging

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get device token using cordova-plugin-firebase-messaging in Cordova?

aravindforums1 opened this issue · comments

Hi, i try to get device token with cordova-plugin-firebase-messaging , but i get empty value, i created app in Firebase console and download google-services and added in root folder. In index.htm file i call that google-services.json. In index.js code as follows.

document.addEventListener('deviceready', onDeviceReady, false); function onDeviceReady() { // Cordova is now initialized. Have fun! //alert("3"); cordova.plugins.firebase.messaging.getToken().then(function(token) { alert("Got device token: ", token); }); }

But i did not get token when open app.
My Cordova version is 11.0.0 and i installed cordova.plugins.firebase.messaging only.
Any reply much appreciated.

Thanks and regards
Aravind

I have the same problem. Getting an empty string or null (haven't checked that yet).

I have the same problem. Getting an empty string or null (haven't checked that yet).

Hi, i can get device token and payload details when passing from firebase, but badge count not showing in app icon in android. Did u try badge count in app icon instead of red dot ?

What have you done to fix the problem that you didn't got an token with the getToken Method?

Since I'm stuck with the first problem (empty token) I haven't tried anything else since I can't send any message to the phone without a token.

What have you done to fix the problem that you didn't got an token with the getToken Method?

Since I'm stuck with the first problem (empty token) I haven't tried anything else since I can't send any message to the phone without a token.

Hi, i installed cordova-plugin-firebase-messaging 7.0.4 "FirebaseMessagingPlugin" plugin and i used following code to get token.

`**document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
cordova.plugins.firebase.messaging.getToken().then(function(token) {
alert(token);
cordova.plugins.firebase.messaging.getBadge(10);
});
}`**

The only problem is i cant show badge count in app icon in Android. Here i hard code the badge count on device ready function, but no luck.