編輯:關於Android編程
String name = new String(response.getBytes("iso-8859-1"), "UTF-8");
也無濟於事。想到服務器好像是用URLENCODER編了碼的,懷著試一試的態度在return後面加了條URLDecoder.decode(content,"utf-8");果然有效!不過還是不太明白URLDecoder.decode(content,"utf-8")和EntityUtils.toString(response.getEntity(),"utf-8")在解碼的時候有什麼區別。下面是網絡端的代碼:
package com.trilink.ibeaconlocationdisplay.utils; import java.io.UnsupportedEncodingException; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.util.EntityUtils; import android.util.Log; public class NetworkService { private static String TAG = "NetworkService"; //private static String url_ip = ServerUrl.SERVER_ADRESS+"UserInfoServlet?"; //private static String url_ip = "http://192.168.1.231:8080/indoor/"; /** * 釋放資源 */ public static void cancel() { Log.i(TAG, "cancel!"); // if(conn != null) { // conn.cancel(); // } } //無參數傳遞的 public static String getPostResult(String url){ //創建http請求對象 HttpPost post = new HttpPost(url); //創建HttpParams以用來設置HTTP參數 BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams,10 * 1000); HttpConnectionParams.setSoTimeout(httpParams, 10 * 1000); //創建網絡訪問處理對象 HttpClient httpClient = new DefaultHttpClient(httpParams); try{ //執行請求參數 HttpResponse response = httpClient.execute(post); //判斷是否請求成功 if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { //獲得響應信息 String content = EntityUtils.toString(response.getEntity()); return URLDecoder.decode(content,"utf-8"); } }catch(Exception e) { e.printStackTrace(); return "{\"status\":405,\"resultMsg\":\"網絡超時!\"}"; } finally { //釋放網絡連接資源 httpClient.getConnectionManager().shutdown(); } return "{\"status\":405,\"resultMsg\":\"網絡超時!\"}"; } //有參數傳遞的 public static String getPostResult(String url, ListparamList){ UrlEncodedFormEntity entity = null; try { entity = new UrlEncodedFormEntity(paramList,"utf-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //創建http請求對象 HttpPost post = new HttpPost(url); BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 10 * 1000); HttpConnectionParams.setSoTimeout(httpParams, 10 * 1000); post.setEntity(entity); //創建網絡訪問處理對象 HttpClient httpClient = new DefaultHttpClient(httpParams); try{ //執行請求參數 HttpResponse response = httpClient.execute(post); //判斷是否請求成功 if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { //獲得響應信息 String content = EntityUtils.toString(response.getEntity(),"UTF-8"); return URLDecoder.decode(content,"utf-8"); } }catch(Exception e) { e.printStackTrace(); return "{\"status\":405,\"resultMsg\":\"網絡超時!\"}"; } finally { //釋放網絡連接資源 httpClient.getConnectionManager().shutdown(); } return "{\"status\":405,\"resultMsg\":\"網絡超時!\"}"; } }
Gradle,這個東西好復雜,不過在Android中,我們知道它大概怎麼用,它的依據何來,就夠了。 build.gradle
之前有人在知乎提問:“怎麼計算apk的啟動時間?”: 利用Python或者直接用adb命令怎麼計算apk的啟動時間呢?就是計算從點擊圖標到apk完
這幾個月都是在做招財進寶項目,一個高收益低風險的理財APP,有興趣的可以下載玩玩,收益不錯哦!!! 招財進寶下載地址:http://8.shengpay.com/
百度一鍵root是一款很簡單清潔的軟件,很適合剛剛接觸root使用的群眾用。root就是讓你的獲取手機權限,然後處理一些手機系統本來無法處理的軟件,讓你的手