PhoneGap构建推送通知(Android)

PhoneGap构建推送通知(Android),android,cordova,push-notification,phonegap-plugins,Android,Cordova,Push Notification,Phonegap Plugins,我在接收任何类型的phonegap构建回调时遇到问题,我已经将插件包含在config.xml中 我已注册并获得pushNotification.register()所需的项目号 我还可以访问window.plugins.pushNotification对象,因此我知道它包含在插件中 PhoneGap构建版本:3.1 水合作用:禁用 调试:已启用 设备:三星标签2 我的index.htmljs文件包括: <script type="text/javascript" src="phoneg

我在接收任何类型的phonegap构建回调时遇到问题,我已经将插件包含在config.xml中

我已注册并获得pushNotification.register()所需的项目号

我还可以访问window.plugins.pushNotification对象,因此我知道它包含在插件中

  • PhoneGap构建版本:3.1
  • 水合作用:禁用
  • 调试:已启用
  • 设备:三星标签2
我的index.htmljs文件包括:

<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="PushNotification.js"></script>
<script type="text/javascript" src="js/lib/jquery.js" ></script>
<script type="text/javascript" src="js/lib/handlebars.js"></script>
<script type="text/javascript" src="js/handlebars/helpers.js"></script>
<script type="text/javascript" src="js/plugins/fastclick.js"></script>
<script type="text/javascript" src="js/app.js"></script>
// plugins
<gap:plugin name="org.apache.cordova.console" />
<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.geolocation" />
<gap:plugin name="org.apache.cordova.dialogs" />
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="org.apache.cordova.splashscreen" />
<gap:plugin name="com.phonegap.plugins.pushplugin" />
// access to external domains
<access origin="*"/>
在调用nothing之后,app.push_android()是app对象的函数

如果我没有输入senderID,我会得到一个错误,说没有发送者ID,这样我就知道有东西在工作。这太令人沮丧了,有什么想法吗


PS-我还注意到一些奇怪的事情,当我在console.log中记录window.plugins.pushNotification时,它返回一个空对象,但是我仍然可以调用window.plugins.pushNotification.register(),但我想我会在console.log中看到。试试这个推送通知代码-

var pushNotification;

document.addEventListener('deviceready', onDeviceReady, true);

function onDeviceReady() {

   try {
       pushNotification = window.plugins.pushNotification;
       if (device.platform == 'android' || device.platform == 'Android') {
           pushNotification.register(successHandler, errorHandler, { "senderID": "123456789", "ecb": "onNotificationGCM" });    // required!
          }
      else {
          pushNotification.register(tokenHandler, errorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" }); // required!
          }
      }  
    catch (err) {
        txt = "There was an error on this page.\n\n";
        txt += "Error description: " + err.message + "\n\n";
        alert(txt);
     }
   };

// handle GCM notifications for Android
function onNotificationGCM(e) {
    switch (e.event) {
        case 'registered':
            if (e.regid.length > 0) {
                alert(e.regid);
                storeToken(e.regid);
            }
            break;

        case 'message':
            if (e.foreground) {
                var my_media = new Media("beep.wav");
                my_media.play();
            }
            else {  
              // otherwise we were launched because the user touched a notification in the notification tray.
            }

            break;

       case 'error':
           break;
       default:
          break;
    }
}
提及


我想我已经找到了解决办法

我传递的是一个整数,而不是对象中senderID属性的字符串

不起作用

pushNotification.register( 
    function(){alert('Push: win');}, // NOT called
    function(){alert('Push: Error');},  // NOT called
    { senderID: 123456789, ecb: "app.push_android" }
);
pushNotification.register( 
    function(){alert('Push: win');}, // called
    function(){alert('Push: Error');},  // called
    { senderID: "123456789", ecb: "app.push_android" }
);
确实有效

pushNotification.register( 
    function(){alert('Push: win');}, // NOT called
    function(){alert('Push: Error');},  // NOT called
    { senderID: 123456789, ecb: "app.push_android" }
);
pushNotification.register( 
    function(){alert('Push: win');}, // called
    function(){alert('Push: Error');},  // called
    { senderID: "123456789", ecb: "app.push_android" }
);

嗨,Suhas,谢谢你的帮助,但这不起作用,没有抛出错误,所以我相信我正在连接到GCM,但没有调用回调函数。它们肯定存在于我的AppGirls中,请参考Devgirls博客。如果您在项目中添加了所有java文件,并将路径正确地放在“plugins.xml”中,那么这应该是可行的。并正确插入pushnotification.js再次感谢,我已经检查了最初的url。正如我在原始帖子中提到的,这不是phonegap CLI,它的phonegap构建,我的www/folder@Suhas还有什么解决办法吗?