안녕하세요. 대학생이며, 어플을 개발하면서 GCM을 같이 써보려구 개발중에 있습니다.
GCM이라는 기능을 사용을 하는데 마음대로 안되어서 질문을 올려봅니다.
google cloude service 에 처음 등록을 하고, regId를 전송받아서 그 regId를 통해 서버에서 어플에 메시지를 전송할 수 있는걸루 대략 알고 있는데요.
문제는 어플을 매번 킬때마다(아예 종료 후) 다시 등록을 시도 하더군요..;;
등록을 하는데도 소스를 보내 random()를 써서 시간이 좀 길고, 그 시간동안 다른 버튼에서 수행해야할 기능이 작동도 안되구요(DB 데이터를 불러와야하는데.. 전혀 안먹더군요)
마땅히 자료조사를 해보았으나, 이런 문제에 대해선 언급이 없어서요..
대략 등록 소스는
if (regId.equals("")) {
// Automatically registers application on startup.
GCMRegistrar.register(this, SENDER_ID);
} else {
// Device is already registered on GCM, check server.
if (GCMRegistrar.isRegisteredOnServer(this)) {
// Skips registration.
//message.append(getString(R.string.already_registered) + "\n");
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
boolean registered = ServerUtilities.register(context, regId);
// At this point all attempts to register with the app
// server failed, so we need to unregister the device
// from GCM - the app will try to register again when
// it is restarted. Note that GCM will send an
// unregistered callback upon completion, but
// GCMIntentService.onUnregistered() will ignore it.
if (!registered) {
GCMRegistrar.unregister(context);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}
};
mRegisterTask.execute(null, null, null);
}
}
입니다.
Q1. 카톡처럼인지 맞는지 모르겠는데요, 처음에 등록한 후에 종료를 하고 다시 어플을 실행시켜도 등록을 안하는법.
Q2. gcm 등록시간이 너무 긴거 같습니다..; 이 시간을 줄이는 방법이 없을까요?
부탁드립니다.