Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GCM字符串而不是布尔值_Java_Android_Json_Boolean_Google Cloud Messaging - Fatal编程技术网

Java GCM字符串而不是布尔值

Java GCM字符串而不是布尔值,java,android,json,boolean,google-cloud-messaging,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 generate

我收到了来自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)
PHP发送脚本

   $devices = array();
   $data = array();
   array_push($devices, getRegId($user_id, $mysqli));
   $data = array("alarm" => true);

   SendGCM(true, $devices, $data);
JSON消息:

{"registration_ids":["APA91bFjtwqq2q5Ji88JjLjuivAzNVGxLDYXaIahCeRUOmaD6vb0T5C22uQSlygztpq_KsVGCZ-0TKQTqUsmp0PU4FXjKYfdsfsdfaxRM1gQ7oh5xHf576-JwQ9FuItsBvhQeQmiKoX3UIi0s3onBh9vO7wI3_Pvw"],"data":{"alarm":true}}
最后是我的OnMessage方法:

@Override
    protected void onMessage(Context context, Intent intent) {

        boolean alarm = false;

        alarm = intent.getBooleanExtra("alarm", false);


    }

当信息发送给您时,它是一个字符串,引用自发送信息,请求格式下的“数据”部分:

值可以是任何JSON对象,但我们建议使用字符串, 因为这些值将在GCM服务器中转换为字符串 无论如何如果要包括对象或其他非字符串数据类型 (例如整数或布尔),必须将其转换为 把你自己绑起来