sid*_*der 2 java android json boolean google-cloud-messaging
我收到了来自GCM的消息,但我得到了字符串而不是布尔值.似乎问题在于我的JSON数组.我收到警告信息:
04-17 00:41:04.058: W/Bundle(6702): Key alarm expected Boolean but value was a java.lang.String. The default value false was returned.
04-17 00:41:04.058: W/Bundle(6702): Attempt to cast generated internal exception:
04-17 00:41:04.058: W/Bundle(6702): java.lang.ClassCastException: java.lang.String
04-17 00:41:04.058: W/Bundle(6702): at android.os.Bundle.getBoolean(Bundle.java:786)
04-17 00:41:04.058: W/Bundle(6702): at android.content.Intent.getBooleanExtra(Intent.java:3282)
04-17 00:41:04.058: W/Bundle(6702): at com.rolandas.lookup.GCMIntentService.onMessage(GCMIntentService.java:71)
04-17 00:41:04.058: W/Bundle(6702): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)
04-17 00:41:04.058: W/Bundle(6702): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
04-17 00:41:04.058: W/Bundle(6702): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 00:41:04.058: W/Bundle(6702): at android.os.Looper.loop(Looper.java:130)
04-17 00:41:04.058: W/Bundle(6702): at android.os.HandlerThread.run(HandlerThread.java:60)
Run Code Online (Sandbox Code Playgroud)
PHP发送脚本.
$devices = array();
$data = array();
array_push($devices, getRegId($user_id, $mysqli));
$data = array("alarm" => true);
SendGCM(true, $devices, $data);
Run Code Online (Sandbox Code Playgroud)
JSON消息:
{"registration_ids":["APA91bFjtwqq2q5Ji88JjLjuivAzNVGxLDYXaIahCeRUOmaD6vb0T5C22uQSlygztpq_KsVGCZ-0TKQTqUsmp0PU4FXjKYfdsfsdfaxRM1gQ7oh5xHf576-JwQ9FuItsBvhQeQmiKoX3UIi0s3onBh9vO7wI3_Pvw"],"data":{"alarm":true}}
Run Code Online (Sandbox Code Playgroud)
最后我的OnMessage方法:
@Override
protected void onMessage(Context context, Intent intent) {
boolean alarm = false;
alarm = intent.getBooleanExtra("alarm", false);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1147 次 |
最近记录: |