是,
推送通知是你的方式..
谷歌提供C2DM作为Android的推送通知服务。
这里 是推送通知的好教程
你的问题没有足够的细节。但我想你想问: 当您的应用程序安装并在设备上运行时,您的服务器会发送消息。 当您的设备收到消息时,它会发送响应。
对的,这是可能的。在安装和运行应用程序时,应该从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 。
您可以。
看一下 : http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests/