C2DM:如何处理第三方php服务器中的注册id?
我已经为C2DM设置了Android部分,下面是部分代码:C2DM:如何处理第三方php服务器中的注册id?,php,android,android-c2dm,Php,Android,Android C2dm,我已经为C2DM设置了Android部分,下面是部分代码: private void handleRegistration(Context context, Intent intent) { // (...) else if (registration != null) { Log.d("c2dm", registration); Editor editor = context.getSharedPreferences(KEY, Context.MOD
private void handleRegistration(Context context, Intent intent) {
// (...)
else if (registration != null) {
Log.d("c2dm", registration);
Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putString(REGISTRATION_KEY, registration);
editor.commit();
// Send the registration ID to the 3rd party site that is sending
// the messages.
// This should be done in a separate thread.
// When done, remember that all registration is done.
}
}
所以它说把注册ID发送到我的服务器。我应该如何处理它,如何用php发送消息
代码示例会很棒,因为我对PHP不是很有经验。我已经看到了答案,但它使用的是会话,而我并没有使用会话。您需要将其保存到MySQL之类的数据库中,以便在以后需要推送到设备时能够访问它 那你就这样寄吧
include("class.c2dm.php");
$c = new C2DM();
$c->setUsername('appemail@gmail.com');
$c->setPassword('emailpassword');
$c->setSource('com.company.app.package');
$c->setAuthCode($c->getAuthCode());
$regid = "longdeviceid"; //this is the device you want to push to. pull from your database.
$response = $c->send($regid, 'TRACK', array('action' => 'start_tracking'));
echo $response;
在此处获取class.c2dm.php:
因此,如果我想通知所有用户,我必须调用
send
方法n
次?是的。你必须做指数退避。因此,如果谷歌说“别挂断,我很忙”,那么在发送更多消息之前,您必须等待x个时间。还有一件事:我如何使用class.c2dm.php发送自定义消息?我想发送随它更改的对象的ID,以便应用程序可以选择是否提取数据。$response=$c->send($regid,'TRACK',array('action'=>'start_tracking')代码>上面写着TRACK,你可以将它更改为你的ID和数组“action”=>“start\u tracking”中的任何额外内容,所以它可能是这样的:$response=$c->send($regid,'1',array('action'=>“update\u news\u feed”)代码>