简体   繁体   English

使用corodova向Android发送消息时出现异常

[英]exception when sending message to android using corodova

I follow the tutorial in this link . 我遵循此链接中的教程。 I could successfully get the reg id back from Google. 我可以成功从Google找回注册ID。 I am using server side script from here But when I send message from server the app crashes and please find my log here 我正在从这里使用服务器端脚本,但是当我从服务器发送消息时,应用崩溃了,请在这里找到我的日志

—–
02-14 17:36:13.684: E/AndroidRuntime(377): FATAL EXCEPTION: IntentService[GCMIntentService-GCMIntentService-2]
02-14 17:36:13.684: E/AndroidRuntime(377): java.lang.NullPointerException: println needs a message
02-14 17:36:13.684: E/AndroidRuntime(377): at android.util.Log.println_native(Native Method)
02-14 17:36:13.684: E/AndroidRuntime(377): at android.util.Log.v(Log.java:116)
02-14 17:36:13.684: E/AndroidRuntime(377): at com.cordova2.gcm.GCMIntentService.onMessage(GCMIntentService.java:63)
02-14 17:36:13.684: E/AndroidRuntime(377): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:179)
02-14 17:36:13.684: E/AndroidRuntime(377): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
02-14 17:36:13.684: E/AndroidRuntime(377): at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 17:36:13.684: E/AndroidRuntime(377): at android.os.Looper.loop(Looper.java:130)
02-14 17:36:13.684: E/AndroidRuntime(377): at android.os.HandlerThread.run(HandlerThread.java:60)
02-14 17:36:13.757: D/DroidGap(377): Paused the application!
——-

what may be the reasons for this issue. 可能是此问题的原因。 Please advice. 请指教。 Regards, Vinod 问候,Vinod

It was a mistake with me. 我错了。 the issue was with the variable name of the server script. 问题出在服务器脚本的变量名上。

if (isset($_GET["regId"]) && isset($_GET["message"])) {
    $regId = $_GET["regId"];
    $message = $_GET["message"];

    include_once './GCM.php';

    $gcm = new GCM();

    $registatoin_ids = array($regId);
    $message = array("price" => $message);

    $result = $gcm->send_notification($registatoin_ids, $message);

    echo $result;
}     . The line $message = array("price" => $message); changed to   $message = array("message" => $message); Now I could get the push message on my android phone. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM