C2DM
分かったようなわからないような。
どこまで,どう使えるのか。
以下だけでいけるはず。
throw Life - addjavascriptinterface
Android開発 C2DMを触ってみよう : アシアルブログ
Sign Up for Android Cloud to Device Messaging - Google Projects for Android
必要なデータの取得
Googleサーバに登録しているアカウント・パスワードで認証トークン(Auth)を取得する。
receive_authtoken.php
<?php $url = 'https://www.google.com/accounts/ClientLogin'; $google_id = 'aaaa@gmail.com'; $google_pwd = 'password'; $header = array('Content-type: application/x-www-form-urlencoded'); $post_list=array('accountType' => 'GOOGLE', 'Email' => $google_id, 'Passwd' => $google_pwd, 'source' => 'sample-sample', 'service' => 'ac2dm'); $post=http_build_query($post_list,'&'); $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_FAILONERROR, 1); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch,CURLOPT_POST, TRUE); curl_setopt($ch,CURLOPT_HTTPHEADER, $header); curl_setopt($ch,CURLOPT_POSTFIELDS, $post); curl_setopt($ch,CURLOPT_TIMEOUT, 5); $ret=curl_exec($ch); var_dump($ret);
プッシュする
認証トークン(Auth) と端末から取得できる 登録端末ID(registeration_id)をGoogleサーバに投げる。
send_message.php
<?php $url = 'https://android.apis.google.com/c2dm/send'; $registration_id = '(登録端末ID)'; $message = 'メッセージ'; $header = array('Content-type: application/x-www-form-urlencoded', 'Authorization: GoogleLogin auth=(認証トークン文字列)'); $post_list = array('registration_id'=> $registration_id, 'collapse_key' => 1, 'data.message' => $message); $post = http_build_query($post_list, '&'); $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_FAILONERROR, 1); curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch,CURLOPT_POST, TRUE); curl_setopt($ch,CURLOPT_HTTPHEADER, $header); curl_setopt($ch,CURLOPT_POSTFIELDS, $post); curl_setopt($ch,CURLOPT_TIMEOUT, 5); $ret=curl_exec($ch); var_dump($ret);
登録端末IDというのは,実機上からアカウントIDとパスワードでGoogleサーバに問い合せて取得する。