編輯:關於android開發
1 import java.io.IOException;
2
3 import org.apache.http.HttpResponse;
4 import org.apache.http.HttpStatus;
5 import org.apache.http.client.ClientProtocolException;
6 import org.apache.http.client.HttpClient;
7 import org.apache.http.client.methods.HttpGet;
8 import org.apache.http.impl.client.DefaultHttpClient;
9 import org.apache.http.util.EntityUtils;
10
11 import android.os.Handler;
12 import android.os.Message;
13 import android.util.Log;
14
15 /**
16 * 開啟線程以Get方式訪問網絡
17 *
18 * @author Administrator
19 *
20 */
21 public class GetThread extends Thread {
22 public static final int SUCCESS = 10, FAIL = -11;
23 private String url;
24 private Handler handler;
25 private String token = "";
26
27 public GetThread(String url, Handler handler) {
28 this.url = url;
29 this.handler = handler;
30 }
31
32 public GetThread(String url, Handler handler, String token) {
33 this.url = url;
34 this.handler = handler;
35 this.token = token;
36 }
37
38 @Override
39 public void run() {
40 // TODO Auto-generated method stub
41 super.run();
42 HttpClient httpClient = new DefaultHttpClient();
43 HttpGet httpGet = new HttpGet(url);
44 if (!token.equals("")) {
45 httpGet.setHeader("Authorization", token);
46 Log.v("asdf", token);
47 }
48
49 try {
50 HttpResponse httpResponse = httpClient.execute(httpGet);
51 Message msg = Message.obtain();
52 Log.v("asdf", httpResponse.getStatusLine().getStatusCode()
53 + "返回碼 " + url);
54 if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
55 String jsonString = EntityUtils.toString(httpResponse
56 .getEntity());
57 msg.what = SUCCESS;
58 msg.obj = jsonString;
59 handler.sendMessage(msg);
60 } else {
61 msg.what = FAIL;
62 handler.sendMessage(msg);
63 }
64
65 } catch (ClientProtocolException e) {
66 e.printStackTrace();
67 } catch (IOException e) {
68 e.printStackTrace();
69 }
70
71 }
72 }
1 import java.io.IOException;
2
3 import org.apache.http.HttpEntity;
4 import org.apache.http.HttpResponse;
5 import org.apache.http.HttpStatus;
6 import org.apache.http.ParseException;
7 import org.apache.http.util.EntityUtils;
8
9 import android.os.Handler;
10 import android.os.Message;
11 import android.util.Log;
12
13 public class PostThread extends Thread {
14 public static final int SUCCESS = 0, FAIL = -1;
15 private Handler handler;
16 private HttpEntity jsonEntity;
17 private String url_path;
18 private boolean isJosn;
19 private String token = "";
20 private String userid = "";
21
22 public PostThread(Handler handler, HttpEntity jsonEntity, String url_path,
23 boolean isJson) {
24 this.handler = handler;
25 this.jsonEntity = jsonEntity;
26 this.url_path = url_path;
27 this.isJosn = isJson;
28 }
29
30 public PostThread(Handler handler, HttpEntity jsonEntity, String url_path,
31 boolean isJson, String userid, String token) {
32 this.handler = handler;
33 this.jsonEntity = jsonEntity;
34 this.url_path = url_path;
35 this.isJosn = isJson;
36 this.userid = userid;
37 this.token = token;
38 }
39
40 @Override
41 public void run() {
42 super.run();
43
44 HttpResponse httpResponse;
45 if (!token.equals("") && !userid.equals("")) {
46
47 Log.v("asdf", token + " -- " + userid);
48 if (isJosn) {
49
50 httpResponse = HttpUtil.getHttpResponse(url_path, jsonEntity,
51 userid, token);
52 } else {
53 httpResponse = HttpUtil.getNormalHttpResponse(url_path,
54 jsonEntity, userid, token);
55 }
56 } else {
57 if (isJosn) {
58 httpResponse = HttpUtil.getHttpResponse(url_path, jsonEntity);
59 } else {
60 httpResponse = HttpUtil.getNormalHttpResponse(url_path,
61 jsonEntity);
62 }
63 }
64
65 Log.v("asdf", "返回碼----》》"
66 + httpResponse.getStatusLine().getStatusCode() + " "
67 + url_path);
68 if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
69
70 try {
71 Message message = Message.obtain();
72 message.what = SUCCESS;
73 message.obj = EntityUtils.toString(httpResponse.getEntity());
74 handler.sendMessage(message);
75 } catch (ParseException e) {
76 e.printStackTrace();
77 } catch (IOException e) {
78 e.printStackTrace();
79 }
80 } else {
81 Message msg = Message.obtain();
82 msg.what = FAIL;
83 handler.sendMessage(msg);
84 }
85 }
86 }
Linux內核系列—5.操作系統開發之特權級及特權級的轉移,linux特權
Linux內核系列—5.操作系統開發之特權級及特權級的轉移,linux特權CPL——當前執行的程序或任務的特權級,它被存儲在cs和ss的第0位和第
我的android學習經歷9,android學習經歷9
我的android學習經歷9,android學習經歷9給android的activity添加背景圖片 1.你可以在網上下載android的圖片,也可以制作自己的圖片,圖片
【原創+譯文】官方文檔中聲明的如何創建抽屜導航欄(Navigation Drawer),navigationdrawer
【原創+譯文】官方文檔中聲明的如何創建抽屜導航欄(Navigation Drawer),navigationdrawer如需轉載請注明出處:http://www.cnbl
淺談Android RecyclerView,androidrecyclerview
淺談Android RecyclerView,androidrecyclerviewAndroid RecyclerView 是Android5.0推出來的,導入supp