0
我想在我的android應用程序上實現谷歌的GCM,我遇到了關於.register()函數的問題。Android GCM:.register功能需要服務器嗎?
private void registerInBackground() {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
Log.d(TAG, "registered gcm");
msg = "Device registered, registration ID=" + regid;
Log.d(TAG, "Current Device's Registration ID is: "+msg);
// You should send the registration ID to your server over HTTP, so it
// can use GCM/HTTP or CCS to send messages to your app.
// sendRegistrationIdToBackend();
// For this demo: we don't need to send it because the device will send
// upstream messages to a server that echo back the message using the
// 'from' address in the message.
// Persist the regID - no need to register again.
storeRegistrationId(context, regid);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
// If there is an error, don't just keep trying to register.
// Require the user to click a button again, or perform
// exponential back-off.
}
return msg;
}
對於REGID = gcm.register(SENDER_ID);,將應用程序利用發送何種類型的連接到GCM以註冊SENDER_ID?它只能通過Wi-Fi來完成,還是需要建立一個服務器才能註冊GCM。我的主要問題是,客戶端應用程序如何向GCM註冊以獲取註冊ID?