阅读背景:

Google Cloud Message:使用JavaScript从Cordova混合应用程序获取RegistrationId

来源:互联网 

I've just started to develop apps for android. I've done an Hybrid Cordova app in telerik platform, so I'm using javascript as language. I need to get push notification sent from a server to my android device. I have a project in Firebase and I set thecorrect google API Key and ProjectId in my code. In order to send the message from the server, I need the Registration ID of my app. How could I get? I found a lot of examples in Java, but none in javascript. Thanks!

我刚刚开始为Android开发应用程序。我在telerik平台上做了一个Hybrid Cordova应用程序,所以我使用javascript作为语言。我需要从服务器发送推送通知到我的Android设备。我在Firebase中有一个项目,我在我的代码中设置了正确的谷歌API密钥和ProjectId。为了从服务器发送消息,我需要我的应用程序的注册ID。我怎么能得到?我在Java中发现了很多例子,但在javascript中没有。谢谢!

1 个解决方案

#1


0  

Use cordova push plugin.You can check the reference here link.

使用cordova push plugin。您可以在这里查看参考链接。

Using that plugin you can get registration Id like this :

使用该插件,您可以获得如下注册ID:

 var push = PushNotification.init({ "android": {"senderID": "YourSenderID"},
    "ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );

push.on('registration', function(data) {
console.log(data.registrationId);
});

分享到: