GCM推送通知,而无需使用JSON [英] GCM Push Notification without using JSON
问题描述
我想从C2DM服务我的应用程序迁移到新的GCM推送通知。我已经成功地延伸GCMBaseIntentService的GCMIntentService类。当我使用PHP从服务器发送推送通知,GCM发送消息数据作为一个JSON对象。我用我的Android GCM服务的以下code,其返回新code空值。
I am trying to migrate my application from C2DM service to new GCM push notification. I have successfully integrated the GCMIntentService class which extends GCMBaseIntentService. When I send the push notification from server using PHP, the GCM sends the message data as a JSON object. I am using the following code in my Android GCM service, and its returning a null value with the new code.
public void onMessage(Context context, Intent intent)
{
String action = intent.getAction();
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
message=intent.getStringExtra("message");
createNotification(context);
}
}
在PHP脚本中包含:
The PHP Script contains :
$头=阵列(
授权:键='。 $ apiKey,
内容类型:应用程序/ JSON
);
$headers = array( 'Authorization: key=' . $apiKey, 'Content-Type: application/json' );
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
请建议我什么都我需要在我的PHP脚本更改为使用GCM库和JSON没有发送推送通知。
Please suggest me what all the changes I require in my PHP script to send the push notification using GCM libraries and without JSON.
在此先感谢
蒂姆·
Thanks in advance Tim
推荐答案
您必须通过JSON发送有效载荷 - 什么原因你不希望使用JSON
you have to send the payload via JSON - whats the reason you do not want to use JSON?
这篇关于GCM推送通知,而无需使用JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!