我正在开发一个应用程序。在其中我使用了运行良好的推送通知功能。
现在我想从
onMessage(Context context, Intent data){
}
并在同一函数中解析后台响应,并将解析后的数据存储在 SQLite 数据库中。
我试图只调用 Web 服务,但出现错误。我的代码如下:
@Override
protected void onMessage(Context context, Intent data) {
String message = data.getStringExtra("message");
if(message != null){
ServiceHandler serviceHandler = new ServiceHandler();
String jsonStr = serviceHandler.makeHttpRequest("http://hostname:1010/test_mf.php", "POST");
Log.d("Response",jsonStr);
//generateNotification(getApplicationContext(), message);
} else {
Log.d("Message","null");
}
}
错误日志如下:
03-13 18:13:26.235: V/GCMBroadcastReceiver(19288): onReceive: com.google.android.c2dm.intent.RECEIVE
03-13 18:13:26.235: V/GCMBroadcastReceiver(19288): GCM IntentService class: com.example.appname.GCMIntentService
03-13 18:13:26.240: V/GCMBaseIntentService(19288): Acquiring wakelock
03-13 18:13:26.265: V/GCMBaseIntentService(19288): Intent service name: GCMIntentService-54442218753-1
03-13 18:13:26.285: V/GCMBaseIntentService(19288): Releasing wakelock
03-13 18:13:26.290: W/dalvikvm(19288): threadid=11: thread exiting with uncaught exception (group=0x4001e578)
03-13 18:13:26.300: E/AndroidRuntime(19288): FATAL EXCEPTION: IntentService[GCMIntentService-54442218753-1]
03-13 18:13:26.300: E/AndroidRuntime(19288): java.lang.NullPointerException
03-13 18:13:26.300: E/AndroidRuntime(19288): at org.apache.http.client.utils.URLEncodedUtils.format(URLEncodedUtils.java:160)
03-13 18:13:26.300: E/AndroidRuntime(19288): at org.apache.http.client.entity.UrlEncodedFormEntity.<init>(UrlEncodedFormEntity.java:71)
03-13 18:13:26.300: E/AndroidRuntime(19288): at com.oi.mobileforgalaxy.webclasses.ServiceHandler.makeHttpRequest(ServiceHandler.java:53)
03-13 18:13:26.300: E/AndroidRuntime(19288): at com.oi.mobileforgalaxy.activity.GCMIntentService.onMessage(GCMIntentService.java:71)
03-13 18:13:26.300: E/AndroidRuntime(19288): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)
03-13 18:13:26.300: E/AndroidRuntime(19288): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
03-13 18:13:26.300: E/AndroidRuntime(19288): at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 18:13:26.300: E/AndroidRuntime(19288): at android.os.Looper.loop(Looper.java:123)
03-13 18:13:26.300: E/AndroidRuntime(19288): at android.os.HandlerThread.run(HandlerThread.java:60)