【问题标题】:exception when sending message to android using corodova使用cordova向android发送消息时出现异常
【发布时间】:2013-02-15 09:46:21
【问题描述】:

我按照this link 中的教程进行操作。我可以成功地从 Google 取回 reg 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!
——-

这个问题的原因可能是什么。请指教。 问候, 维诺德

【问题讨论】:

  • 你能显示导致崩溃的代码行吗?
  • 我用谷歌搜索了这个例外,发现了这个stackoverflow.com/questions/6018633/…
  • 请找到代码(编辑器不允许我放所有类):package com.cordova2.gcm; import ........ public class GCMIntentService extends GCMBaseIntentService { public static final String ME="GCMReceiver";公共 GCMIntentService() { super("GCMIntentService"); } private static final String TAG = "GCMIntentService";
  • 和更多受保护的 void onMessage(Context context, Intent intent) { Log.d(TAG, "onMessage - context:" + context); // 从消息中提取有效负载 Bundle extras = intent.getExtras(); if (extras != null) { try { Log.v(ME + ":onMessage extras ", extras.getString("message")); JSON对象 json; json = new JSONObject().put("事件", "消息"); // 我的主机服务器上的应用程序发送回“EXTRAS”变量消息和 msgcnt // 根据您构建服务器应用程序的方式,您可以指定要发送的变量
  • 错误发生在"Log.v(ME + ":onMessage extras", extras.getString("message"));"行

标签: android cordova push-notification


【解决方案1】:

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

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. 

【讨论】:

    猜你喜欢
    • 2017-12-06
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 2018-05-12
    • 2012-10-12
    • 2012-12-16
    • 2021-05-23
    • 1970-01-01
    相关资源
    最近更新 更多