2013-01-10 25 views
0

每一個Google Cloud Messaging For Android (GCM) Simple Tutorial收到,我已經創建了一個使用GCM服務推送通知Android應用程序。現在我成功地在設備或模擬器中獲取通知,但問題是我只能在一個設備(用於測試的設備)中獲取,而不是在其他應用程序安裝的設備中。Android的推送通知只能由一個設備

final String regId = GCMRegistrar.getRegistrationId(this); 

使用此代碼我收到的註冊ID,我從logcat的窗口,複製和手動發送到我的.NET開發人員的輸出。他在服務器端複製該ID,因此對於該設備,我收到通知。請幫我將該註冊ID動態地發送到服務器端(Asp.net服務器)。以便他可以將這些ID存儲在數據庫中,並將註冊ID數組傳遞給Google GCM服務器。我認爲只有我們可以得到所有設備(安裝的應用程序)的通知。因爲現在在服務器端,我們將數據傳遞到GCM服務器以這樣的方式

string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + deviceIDs + ""; 

請糾正我,如果我的程序是怎麼了地方。

回答

1

基本上你想要做的是開放的數據連接到Web服務器,並與手機的其他一些鑑定因子發送您gcmid它(如用戶ID或電話ID),你會想在GCMIntentService類的OnRegistered方法中執行此操作。我發送表單發佈請求到網絡服務器。在網絡服務器上,您可能需要將信息存儲在數據庫中。 我使用多維數組作爲我的表單變量

public String formPost(String[][] Vars) { 

    String url = "put url of web server here"; 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpPost httppost = new HttpPost(url); 
    String tmp = null; 
    String rturn = null; 
    try { 
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
     for (int i = 0; i < Vars.length; i++) { 
      nameValuePairs.add(new BasicNameValuePair(Vars[i][0], Vars[i][1])); 
     } 
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
     HttpResponse response = httpclient.execute(httppost); 
     String ttmp = parseISToString(response.getEntity().getContent()); 
     Log.i("test", ttmp); 
     if (ttmp.contains("Success")) { 
      rturn = ttmp; 
      Log.i("test", "Success:" + ttmp); 
     } else { 
      rturn = ttmp; 
      Log.i("test", "Fail:" + ttmp); 
     } 

    } catch (ClientProtocolException e) { 

    } catch (IOException e) { 
    } /* 
    * catch (RuntimeException e){ Context context = 
    * getApplicationContext(); CharSequence text = 
    * "There was an error try again later."; int duration = 
    * Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, 
    * duration);toast.show(); Log.i("test",e.getMessage()); finish(); } 
    */ 
    return rturn; 

} 
+0

謝謝您的回覆David。有一些疑問。我上面編輯過。 – KKC

+0

嗨Zhydian,感謝您對烏爾響應,有一些其他quaries, – KKC

+0

這將是巨大的,如果清除過,我給了我的疑問,作爲另一question..please指的link..http://stackoverflow.com/問題/ 14318115 /推送通知,使用-GCM-與-ASP淨服務器功能於androidhow到獲得-和發送-I – KKC

相關問題