我正在为Android Cordova 2.2.0进行推送通知
我已经按照PushPlugin page上列出的所有说明进行操作,但是每当我尝试注册设备时,都会出现错误,并且该应用程序只是关闭/关闭,这是在我的Android手机上进行测试时发生的
在android虚拟机上,我从logcat得到以下信息:
02-19 21:48:31.152: D/SoftKeyboardDetect(383): Ignore this event
02-19 21:48:31.302: V/PushPlugin(383): execute: action=register
02-19 21:48:31.322: V/PushPlugin(383): execute: data= [{"senderID":391440660838,"ecb":"onNotificationGCM"}]
02-19 21:48:31.322: V/PushPlugin(383): execute: jo= {"senderID":391440660838,"ecb":"onNotificationGCM"}
02-19 21:48:31.352: D/AndroidRuntime(383): Shutting down VM
02-19 21:48:31.352: W/dalvikvm(383): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-19 21:48:31.392: E/AndroidRuntime(383): FATAL EXCEPTION: main
02-19 21:48:31.392: E/AndroidRuntime(383): java.lang.ClassCastException: java.lang.Long
02-19 21:48:31.392: E/AndroidRuntime(383): at com.plugin.gcm.PushPlugin.execute(PushPlugin.java:63)
02-19 21:48:31.392: E/AndroidRuntime(383): at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:61)
02-19 21:48:31.392: E/AndroidRuntime(383): at org.apache.cordova.api.PluginManager.exec(PluginManager.java:224)
02-19 21:48:31.392: E/AndroidRuntime(383): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:43)
02-19 21:48:31.392: E/AndroidRuntime(383): at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:213)
02-19 21:48:31.392: E/AndroidRuntime(383): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
02-19 21:48:31.392: E/AndroidRuntime(383): at android.os.Handler.dispatchMessage(Handler.java:99)
02-19 21:48:31.392: E/AndroidRuntime(383): at android.os.Looper.loop(Looper.java:123)
02-19 21:48:31.392: E/AndroidRuntime(383): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-19 21:48:31.392: E/AndroidRuntime(383): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 21:48:31.392: E/AndroidRuntime(383): at java.lang.reflect.Method.invoke(Method.java:507)
02-19 21:48:31.392: E/AndroidRuntime(383): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-19 21:48:31.392: E/AndroidRuntime(383): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-19 21:48:31.392: E/AndroidRuntime(383): at dalvik.system.NativeStart.main(Native Method)
02-19 21:49:32.252: I/Process(383): Sending signal. PID: 383 SIG: 9
我已经重新检查了页面上的所有内容并按照说明进行了操作,但是当我尝试注册设备时,该应用程序仍然关闭。
最佳答案
您得到的错误是:
02-19 21:48:31.392:E / AndroidRuntime(383):
java.lang.ClassCastException:java.lang.Long 02-19
21:48:31.392:E / AndroidRuntime(383):在
com.plugin.gcm.PushPlugin.execute(PushPlugin.java:63)
PushPlugin.java:63是:
gSenderID = (String) jo.get("senderID");
似乎该行正在尝试将Long转换为String。我认为问题出在这里:
execute: jo= {"senderID":391440660838,"ecb":"onNotificationGCM"}
我不知道
jo
JSON的初始化方式,但应该将其更改为:execute: jo= {"senderID":"391440660838","ecb":"onNotificationGCM"}
您应该用引号将数字引起来。
编辑:
查看发布的链接中的说明,您肯定忘记了发件人ID周围的引号:
if ( device.platform == 'android' || device.platform == 'Android' )
{
pushNotification.register(
successHandler,
errorHandler, {
"senderID":"replace_with_sender_id",
"ecb":"onNotificationGCM"
});
}