android 百度翻译开发,这段代码在android 3.0以下版本是可以执行的,在4.0上就只能执行到HttpResponse response = httpClient.execute(httpPost); 求解
try{
HttpEntity httpEntity = new UrlEncodedFormEntity(postParams,HTTP.UTF_8);
HttpPost httpPost = new HttpPost(urlApi);
HttpClient httpClient = new DefaultHttpClient();
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setEntity(httpEntity);
HttpResponse response = httpClient.execute(httpPost);
if(response.getStatusLine().getStatusCode()==200){
String strResult=EntityUtils.toString(response.getEntity());
jsonObject =new JSONObject(strResult);
JSONArray json = jsonObject.getJSONArray("trans_result");
String showMessage="";
for(int i =0;i<json.length();i++){
JSONObject data =(JSONObject)json.get(i);
showMessage +=data.getString("dst");
}
ToText.setText(showMessage);
}else{
ToText.setText("Error Response"+response.getStatusLine().toString());
}
}
catch(Exception e){
Log.i("BaiduTrans.java", "百度翻译异常");
}
大家好 ,问题我已经解决了