2012-03-02 194 views

回答

2

是,

推送通知你的方式去..

谷歌提供C2DM作爲Android的推送通知服務。

Here是推送通知

0

你的問題沒有足夠的細節很好的教程。但我想你想問: 由於你的應用程序安裝並運行在設備上,你的服務器發送一條消息。 由於您的設備收到消息,它會發送響應。

是的,這是可能的。隨着應用程序的安裝和運行,您應該使用onCreate或onStart方法調用您的servlet。隨着您的服務器消息收到,您將再次從您的設備發送消息。 段:

HttpClient client = new DefaultHttpClient(); 
String getURL = "http://www.yourserver/servlet"; 
HttpGet get = new HttpGet(getURL); 
HttpResponse responseGet = client.execute(get); 
HttpEntity resEntityGet = responseGet.getEntity(); 
if (resEntityGet != null) { 
    //do something with the response 
    //or call another url hit with your message 
} 

和第二請求響應上接收是

 HttpClient client = new DefaultHttpClient(); 
     String postURL = "http://yourserver"; 
     HttpPost post = new HttpPost(postURL); 
     List<NameValuePair> params = new ArrayList<NameValuePair>(); 
     params.add(new BasicNameValuePair("message", "your message")); 
     UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8); 
     post.setEntity(ent); 
     HttpResponse responsePOST = client.execute(post); 
     HttpEntity resEntity = responsePOST.getEntity(); 
     if (resEntity != null) {  
      Log.i("RESPONSE",EntityUtils.toString(resEntity)); 
     } 

--------------------------編輯---------------

您應該通過C2DM。這是針對Android設備的推送通知服務,您必須按照C2DM的整個過程進行操作。

+0

對不清楚的問題。我的意思是這條消息是從服務器端發送的,並且是由服務器創建的,例如android設備通過servlet接收來自其他用戶的消息 – user1244556 2012-03-02 08:29:23

相關問題