, 당신은 당신의 주요 활동에서 다음을 수행해야합니다이 응용 프로그램은 registration_id
추가로 의도 com.google.android.c2dm.intent.REGISTRATION
를 수신 할 때마다
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, GCMIntentService.GCM_SENDER_ID);
} else {
Log.v(TAG, "Already registered");
}
}
는 그 후에 당신은 당신의 애플 리케이션 서버, 에 등록 ID를 보내야합니다. 이것은 Google이 주기적으로 앱의 ID를 업데이트 할 때 발생할 수 있습니다.
당신은
public class GCMIntentService extends GCMBaseIntentService {
// Also known as the "project id".
public static final String GCM_SENDER_ID = "XXXXXXXXXXXXX";
private static final String TAG = "GCMIntentService";
public GCMIntentService() {
super(GCM_SENDER_ID);
}
@Override
protected void onRegistered(Context context, String regId) {
// Send the regId to your server.
}
@Override
protected void onUnregistered(Context context, String regId) {
// Unregister the regId at your server.
}
@Override
protected void onMessage(Context context, Intent msg) {
// Handle the message.
}
@Override
protected void onError(Context context, String errorId) {
// Handle the error.
}
}
자세한 내용은, 내가 (다시) 것 : 자신의 구현 com.google.android.gcm.GCMBaseIntentService
을 확장하여 예컨대을이를 writing the client side code 및 the Advanced Section of the GCM documentation에 대한 문서를 읽을 수 있습니다.
희망 하시겠습니까?
[Android에서 Google 클라우드 메시징의 등록 ID 변경 처리] (http://stackoverflow.com/questions/16838654/handling-registration-id-changes-in-google-cloud-messaging-on) 중복 가능 -기계적 인조 인간) – Eran