手机间隙中的android推送通知未收到通知

手机间隙中的android推送通知未收到通知,android,cordova,phonegap-plugins,Android,Cordova,Phonegap Plugins,嗨,我遵循下面的步骤 1) 我创建了cordova项目结构。 2) 我添加了平台(android)。 3) 我添加了cordova插件 cordova plugin add https://github.com/phonegap-build/PushPlugin.git#2.4.0 4) 创建科尔多瓦项目。 5) 接下来,我将在android eclipse(4.4.2)中导入创建的应用程序 6) 我在index.js文件中编写了下面的代码 init: function(){ al

嗨,我遵循下面的步骤

1) 我创建了cordova项目结构。
2) 我添加了平台(android)。
3) 我添加了cordova插件

cordova plugin add https://github.com/phonegap-build/PushPlugin.git#2.4.0
4) 创建科尔多瓦项目。
5) 接下来,我将在android eclipse(4.4.2)中导入创建的应用程序
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.
        }
    };
我得到的响应是“OK”。我无法调用'ecb':onNotificationGCM'//回调函数

在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().

这是推送通知流:

  • 您的应用程序请求注册到远程Apple或Google服务器
  • 如果注册正常,删除服务器将返回一个令牌,用于标识设备上的此特定应用
  • 将此令牌发送到服务器并保存(例如,在db上)
  • 您(从您的服务器)发送一个推送通知,呼叫Apple或Google services,其中包含您想要通知的用户的消息和令牌
  • 这些服务向您的设备/应用程序推送带有消息的通知
  • 您必须遵循所有这些步骤才能使推送通知生效

    对于android,您需要捕获通知处理程序的
    registed
    事件中的注册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.
        }
    };
    
    对于iOS,您需要在
    register
    函数的后续处理程序中捕获它


    有关更多信息,请查看。

    您在GCM中注册了吗?是的,我已注册了您是否获得了GCM注册ID?否,我没有获得任何GCM注册ID,我正在发送senderIDin successHandler函数,我收到的响应为“确定”如何获得注册ID我没有收到内部警报(“提交”);