2013-09-24 55 views
0

我跟隨this example爲GCM工作正常只是告訴我如何服務器發送消息到每個註冊設備如何將唯一標識每個設備的機制。我SENDER_ID是什麼regId如何服務器唯一識別我的設備PHP服務器如何發送消息到多個設備,而無需SMS電子郵件服務告訴我它的機制,請將如何在這個應用程序的工作 我很少有這樣如何GCM服務器註冊ID和什麼是發送消息的機制

String SENDER_ID = "748495904142" 

我從https://code.google.com/apis/console/?pli=1#project:748495904142:access

final String regId = GCMRegistrar.getRegistrationId(this); 

// Check if regid already presents 
if (regId.equals("")) { 
    // Registration is not present, register now with GCM   
    GCMRegistrar.register(this, SENDER_ID); 
} else { 
    // Device is already registered on GCM 
    if (GCMRegistrar.isRegisteredOnServer(this)) { 
     // Skips registration.    
     Toast.makeText(getApplicationContext(),"Already registered with GCM", 
     Toast.LENGTH_LONG).show(); 
    } 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) { 
       // Register on our server 
       // On server creates a new user 
       ServerUtilities.register(context, name, email, regId); 
       return null; 
      } 

      @Override 
      protected void onPostExecute(Void result) { 
       mRegisterTask = null; 
      } 
     }; 
    } 
} 
+0

應用程序運行完美我只是想知道什麼是後端什麼是SENDER_ID什麼是regId如何php服務器消息到每個設備 – user2806157

回答

1

SENDER_ID收到是服務器使用與服務器相關聯的不同項目之間進行區分項目的ID。

REG_ID是服務器用來區分註冊到服務器的不同移動設備的唯一ID。

現在,例如,同一移動設備與兩個不同的項目相關聯並且與同一服務器相關聯,因此爲服務器提供了區分兩個項目並向移動設備發送相應消息的簡易性。

0

當您在API控制檯上註冊項目時,您爲項目獲得了一個數字,該數字就是SENDER_ID,您還可以從控制檯獲取API密鑰。在Android的執行

final String regId = GCMRegistrar.getRegistrationId(this);

然後用GCM註冊移動檢查,如果已經與GCM服務器上註冊,然後它會返回一個的RegID。這些ID對於不同的手機而言是不同的。 gcm服務器使用此註冊ID識別您的手機。獲得regid後,我們將其保存到我們的數據庫以供將來使用。在服務器端,我們只是將消息和註冊ID發送到gcm服務器,gcm服務器通過使用註冊ID來識別電話並將通知發送到適當的移動設備。

相關問題