0
我需要上傳和下載包含緯度,經度和最後一次從mysql-php通過電子郵件過濾看到的3個字段。什麼是Android最快和最少的內存消耗方法?上傳或下載經緯度最長的服務器最快的方法
在後臺嘗試異步,但需要大約10秒才能返回。
公共類LocationWebService擴展的AsyncTask {
public LocationWebService() {
// TODO Auto-generated constructor stub
}
@Override
protected Boolean doInBackground(String... arg0) {
String lat = arg0[0];
String lng = arg0[1];
String url = arg0[2];
String email = arg0[3];
Log.e("LAT",arg0[0]);
Log.e("LNG",arg0[1]);
Log.e("URL",arg0[2]);
Log.e("EMAIL",arg0[3]);
InputStream is = null;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("latitude", lat));
nameValuePairs.add(new BasicNameValuePair("longitude", lng));
nameValuePairs.add(new BasicNameValuePair("email", email));
String result = null;
try{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
請添加你試過的東西? –
不要用戶HtttpClient。其棄用。嘗試翻新或排球圖書館。去谷歌上查詢 –