[英]android push notification in phone gap not getting notifications
Hi I follow the steps below 嗨,我按照以下步骤
1) I created the cordova project structure. 1)我创建了cordova项目结构。
2) I added the platform( android). 2)我添加了平台(android)。
3) I added the cordova plugin 3)我添加了cordova插件
cordova plugin add https://github.com/phonegap-build/PushPlugin.git#2.4.0
4) Bulid the cordova project. 4)编译cordova项目。
5) Next I import the created app in android eclipse(4.4.2) 5)接下来,我将创建的应用程序导入android eclipse(4.4.2)
6) I wrote the code below in index.js
file 6)我在
index.js
文件中编写了以下代码
init: function(){
alert("init");
var pushNotification = window.plugins.pushNotification;
pushNotification.register(successHandler, errorHandler,
{
'senderID':'XXXXXXXXXX',
'ecb':'onNotificationGCM' // callback function
}
);
function successHandler(result) {
console.log('Success: '+ result);
alert(result);
}
function errorHandler(error) {
console.log('Error: '+ error);
}
function onNotificationGCM(e) {
alert("comming");
if('registered' === e.event) {
// Successfully registered device.
}
else if('error' === e.event) {
// Failed to register device.
}
};
I am getting the respose as "OK".and i am not able call 'ecb': onNotificationGCM' // callback function 我得到的respose为“ OK”。我无法调用“ ecb”:onNotificationGCM'//回调函数
In Android console I am getting the bellow Message 在Android控制台中,我收到以下消息
V/PushPlugin(2512): execute: action=register
V/PushPlugin(2512): execute: data= [{"senderID":"889953963751","ecb":"onNotificationGCM"}] V/PushPlugin(2512): execute: jo={"senderID":"889953963751","ecb":"onNotificationGCM"} V/PushPlugin(2512): execute: ECB=onNotificationGCM senderID=889953963751
09-12 03:13:33.453: D/GCMRegistrar(2512): resetting backoff for com.ensis.hello
09-12 03:13:33.613: V/GCMRegistrar(2512): Registering app com.ensis.hello of senders 889953963751
09-12 W/PluginManager(2512): THREAD WARNING: exec() call to PushPlugin.register blocked the main thread for 181ms. Plugin should use CordovaInterface.getThreadPool().
This is the push notification flow: 这是推送通知流程:
You must follow all these steps in order to have push notification working. 您必须执行所有这些步骤才能使推送通知正常工作。
For android you need to catch the registration id (token) inside the registered
event of the notification handler: 对于android,您需要在通知处理程序的
registered
事件内捕获注册ID(令牌):
function onNotificationGCM(e) {
alert("comming");
if('registered' === e.event) {
// Successfully registered device.
console.log("regID = " + e.regid);
// save/send this registration id on your server
} else if('error' === e.event) {
// Failed to register device.
}
};
For iOS you need to catch it in the succesHandler of the register
function. 对于iOS,您需要在
register
函数的succesHandler中捕获它。
For more information look at this example in the plugin repository . 有关更多信息,请参阅插件存储库中的此示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.