使用cordova向android发送消息时出现异常

tyu7yeag  于 2022-11-15  发布在  Android
关注(0)|答案(1)|浏览(153)

我按照这个链接中的教程操作。我可以成功地从Google获取注册表ID。我正在使用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!
——-

这个问题的原因可能是什么?

bf1o4zei

bf1o4zei1#

这是我的一个错误。问题是服务器脚本的变量名。

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.

相关问题