我正在研究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
我已经重新检查了页面上的所有内容并按照说明操作,但当我尝试注册设备时,应用仍会关闭。
答案 0 :(得分:1)
您得到的错误是:
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"
});
}