안녕하세요.
안드로이드폰에서 어플을 처음 실행 시 regid를 서버로 보내주고 서버에서 그 즉시 authtoken을 만들고
그 다음 바로 regid를 포함해서 c2dm서버로 보내게 됩니다. 그러면 리턴값이 id=0.어쩌구저쩌구 나오는데요.
id값이 나온다는 거는 정상동작이라고 봤는데 왜 제 단말기에는 오지 않는걸까요? 제 단말기는 갤럭시s입니다.
소스에 문제가 있는 것인지 한번 봐주시고 댓글 달아주시면 고맙겠습니다. 이거가지고 시간을 너무 허비하고 있네요..ㅜㅜ
# php서버
function googleAuthenticate($username, $password) {
$source="testk-1.0";
$service="ac2dm";
//session_start();
if( isset($_SESSION['google_auth_id']) && $_SESSION['google_auth_id'] != null)
return $_SESSION['google_auth_id'];
// get an authorization token
$ch = curl_init();
if(!ch){
return false;
}
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
$post_fields = "accountType=" . urlencode('HOSTED_OR_GOOGLE')
."&Email=" . urlencode($username)
."&Passwd=" . urlencode($password)
. "&source=" . urlencode($source)
."&service=" . urlencode($service);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
if (strpos($response, '200 OK') === false) {
return false;
}
preg_match("/(Auth=)([\w|-]+)/", $response, $matches);
if (!$matches[2]) {
return false;
}
$_SESSION['google_auth_id'] = $matches[2];
return $matches[2];
}
function sendMessageToPhone($authCode, $deviceRegistrationId, $messageText) {
$headers = array('Authorization: GoogleLogin auth=' . $authCode);
$data = array(
'registration_id' => $deviceRegistrationId,
'collapse_key' => '1',
'data.message' => $messageText
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send");
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
print $deviceRegistrationId;
print $response;
return $response;
}
$auth = googleAuthenticate( $email, $pw);
sendMessageToPhone( $auth, $regId, $path );
# 안드로이드폰
@Override
public void onReceive(Context context, Intent intent) {
this.ctx = context;
String c2dm_msg = null;
// 등록을 하는 경우
if (intent.getAction().equals(
"com.google.android.c2dm.intent.REGISTRATION")) {
handleRegistration(context, intent);
}
// 푸쉬 메시지를 받은 경우 Notification으로 메시지 보이기
else if (intent.getAction().equals(
"com.google.android.c2dm.intent.RECEIVE")) {
c2dm_msg = intent.getExtras().getString("message");
Log.d(TAG, intent.getExtras().toString());
setNotification(c2dm_msg);
}
}




자답입니다.
구글토크 로그인 상태로 해놓으면 c2dm 인텐트 필터 충돌때문에 안되는 것 같습니다.
구글 토크를 로그아웃 시키면 잘 날라옵니다.
이런 치명적인 버그를 보완하는 방법은 없을까요? 이것땜에 2틀 날렸네요.ㅎㅎㅎ 꼼꼼한 성격이였으면 빨리 알아차렸을 텐데..