我试图让GCM Cordova Plugin在提供的示例应用程序中运行。我下载了源代码,并在Eclipse中创建了一个来自现有代码的项目。Cordova/Phonegap用于Android崩溃的GCM插件
现在,在这个项目中有一个名为CORDOVA_GCM_script.js文件,其中有必要更改发件人ID来与我自己的GCM服务标识符(这是我从我的谷歌项目获得):
window.plugins.GCM.register("my_sender_id", "GCM_Event", GCM_Success, GCM_Fail);
要将信息发送给我的申请,我用Node.js的这个剧本,就如同上this post解释冬青Schinsky提供:
var GCM = require('gcm').GCM;
var apiKey = 'someCharsRepresentingMyKey';
var gcm = new GCM(apiKey);
var message = {
registration_id: 'myDeviceRegistrationId', // required
collapse_key: 'demo',
'message': 'Yourturn',
'title': 'My Game',
'msgcnt': '1'
};
gcm.send(message, function(err, messageId){
if (err) {
console.log("Something has gone wrong!");
} else {
console.log("Sent with message ID: ", messageId);
}
});
现在,当我在设备上运行的应用,它开始和被注册但是当我尝试向它发送消息时,它很难畲族与消息存在“不幸的是,GCM已停止”
logcat的显示我:
03-05 20:15:39.897: E/AndroidRuntime(19007): FATAL EXCEPTION: IntentService[GCMIntentService-GCMIntentService-2]
03-05 20:15:39.897: E/AndroidRuntime(19007): java.lang.NullPointerException: println needs a message
03-05 20:15:39.897: E/AndroidRuntime(19007): at android.util.Log.println_native(Native Method)
03-05 20:15:39.897: E/AndroidRuntime(19007): at android.util.Log.v(Log.java:117)
03-05 20:15:39.897: E/AndroidRuntime(19007): at com.cordova2.gcm.GCMIntentService.onMessage(GCMIntentService.java:63)
03-05 20:15:39.897: E/AndroidRuntime(19007): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:179)
03-05 20:15:39.897: E/AndroidRuntime(19007): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
03-05 20:15:39.897: E/AndroidRuntime(19007): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 20:15:39.897: E/AndroidRuntime(19007): at android.os.Looper.loop(Looper.java:137)
03-05 20:15:39.897: E/AndroidRuntime(19007): at android.os.HandlerThread.run(HandlerThread.java:60)
我发现this post跟着提出劝告,但应用程序总是崩溃。
任何人都可以给我任何建议吗?
谢谢。
正如你所建议的,我评论了两条线。 。 。应用程序不再崩溃,并且在WebView上我可以看到“MESSAGE - > MSG:undefined”和“MESSAGE - > MSGCOUNT:undefined”这两行,这表明我可能没有以正确的方式从服务器发送消息。 – Octavio 2013-03-05 20:46:38