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?