編輯:關於Android編程
簡單 方便
/**
* @author think
*以同步方式發送Http請求
*/
public class ApacheHttpClient {
/**
* @return
*
*/
public String httpGet(String uri) {
String response=null;//響應
HttpClient httpClient=new DefaultHttpClient();
//創建HttpGet對象
HttpGet httpGet=new HttpGet(uri);
HttpResponse httpResponse;
try {
//使用execute方法發送HTTP GET請求,並返回HttpResponse對象
httpResponse=httpClient.execute(httpGet);
int statusCode = httpResponse.getStatusLine().getStatusCode();//返回碼 ,
if (statusCode==HttpStatus.SC_OK) {
//獲得返回結果
response=EntityUtils.toString(httpResponse.getEntity());
}
else {
response = "返回碼:"+statusCode;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();}
System.out.println(response);
return response;
}
/**
* 以Post方式發送請求
* @param url 請求地址
* @param params 參數 ,Post方式必須用NameValuePair[]陣列儲存參數
* @return
* @throws Exception
*/
public String httpPost(String uri,List params) throws Exception{
String response=null;
HttpClient httpClient=new DefaultHttpClient();
HttpPost httpPost=new HttpPost(uri);
try {
//設置httpPost請求參數
httpPost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
//使用execute方法發送HTTP Post請求,並返回HttpResponse對象
HttpResponse httpResponse=httpClient.execute(httpPost);
int statusCode = httpResponse.getStatusLine().getStatusCode();//返回碼 ,
if (statusCode==HttpStatus.SC_OK) {
response=EntityUtils.toString(httpResponse.getEntity());
System.out.println("______________"+response);
}
else {
response = "返回碼:"+statusCode;
System.out.println("______________"+response);
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
}
Android 6.0 動態權限申請詳解
1.介紹Runtime Permissions官方說明Android 6.0之前,權限在應用安裝過程中只詢問一次,以列表的形式展現給用戶,然而大多數用戶並不會注意到這些,
Android studio share項目到svn倉庫
我們有新的項目要進行開發了,一直想用用android studio。所以在新項目上,果斷使用。這裡是我將android studio項目share到svn倉庫的全過程。後
android 關於屏幕截屏的幾種辦法
年末較閒,就上個星期查找各方面的資料關於android截圖事情,自已也測試一些代碼,已改改進或者優化。接下來進行總結一下。其實,如果真正android系統截屏是需要roo
Android App開發中RecyclerView控件的基本使用教程
概述RecyclerView出現已經有一段時間了,相信大家肯定不陌生了,大家可以通過導入support-v7對其進行使用。 據官方的介紹,該控件用於在有限的窗口中展示大量
Android中通過ViewHelper.setTranslationY實現View移動控制(NineOldAndroids開源項目)
我們知道有不少開源工程,能實現很多不錯的效果。前幾天,我看了一個效果,剛