Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓÆµ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Modeler   Code  
»áÔ±   
 
   
 
 
     
   
 ¶©ÔÄ
  ¾èÖú
°²×¿µÚ°ËÌì±Ê¼Ç--ÍøÂç±à³Ì¶þ
 
×÷ÕߣºÉ­ÁÖÉ­ À´×ÔÓÚ£º²©¿ÍÔ° ·¢²¼ÓÚ 2016-3-23
  2103  次浏览      27
 

1.ÍøÂçͼƬ²é¿´Æ÷

ÍøÂçͼƬ²é¿´Æ÷

1.»ñÈ¡ÊäÈëµÄURLµØÖ·,ÅжÏÊÇ·ñΪ¿Õ

2.½¨Á¢×ÓÏß³Ì,»ñÈ¡URl¶ÔÏónew URL(path)

3.´ò¿ªÁ¬½Ó»ñÈ¡HttpURLConnection conn = (HttpURLConnection) url.openConnection();

4.ÉèÖÃÁ¬½Ó³¬Ê±Ê±¼äconn.setConnectionTimeOut(5000)ºÁÃë

5.ÉèÖÃÇëÇó·½Ê½setRequestMethod

GET»òÕßPOSTÒª´óд

6.»ñÈ¡ÏìÓ¦Âë conn.getResponseCode()

7.ÅжÏÊDz»ÊÇ200,ÊÇ200¾ÍÒ»ÇÐÕý³£

8.»ñÈ¡conn.getInputStream() ,

9.ʹÓÃBitmapFactory.decode(in),½«Á÷ת»»ÎªBitmap¶ÔÏó

10.ʹÓÃMessage msg = Message.obtain(),

11.ÉèÖÃmsg.whatÊÇint ÀàÐÍÓÃÀ´±íʾ±êʶ

·ûÈçSUCCESS,ERROR Óëmsg.objΪObjectÀàÐÍmsg.obj=bitmap,ÓÃÀ´´«µÝÊý¾Ý

12.handler.sendMessage(msg)·¢Ë͸øÖ÷Ï̵߳ÄHandler¶ÔÏó

13.Ö÷Ïß³ÌÖÐHandler handler = newHandler(){

ÖØÐ´handleMessage·½·¨ ÅжÏmsg.what,×öÖ÷Ïß³ÌÖеÄUI¸üлòÕßÌáʾÓû§´íÎóÐÅÏ¢}

14.Ìí¼ÓÍøÂçȨÏÞInternet

²¼¾Ö

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

<!--ÊäÈëURLͼƬµØÖ· -->

<EditText

android:id="@+id/et_path"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="http://188.188.3.79:8080/itest/test.png" />

<Button

android:onClick="display"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="ÏÔʾͼƬ"/>

<ImageView

android:id="@+id/iv_show"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

</LinearLayout>

Activity

* ÍøÂçͼƬ²é¿´Æ÷

* 1.»ñÈ¡ÊäÈëµÄURLµØÖ·,ÅжÏÊÇ·ñΪ¿Õ

* 2.½¨Á¢×ÓÏß³Ì,»ñÈ¡URl¶ÔÏónew URL(path)

* 3.´ò¿ªÁ¬½Ó»ñÈ¡HttpURLConnection conn = (HttpURLConnection) url.openConnection();

* 4.ÉèÖÃÁ¬½Ó³¬Ê±Ê±¼äconn.setConnectionTimeOut(5000)ºÁÃë

* 5.ÉèÖÃÇëÇó·½Ê½setRequestMethod

* GET»òÕßPOSTÒª´óд

* 6.»ñÈ¡ÏìÓ¦Âë conn.getResponseCode()

* 7.ÅжÏÊDz»ÊÇ200,ÊÇ200¾ÍÒ»ÇÐÕý³£

* 8.»ñÈ¡conn.getInputStream() ,

* 9.ʹÓÃBitmapFactory.decode(in),½«Á÷ת»»ÎªBitmap¶ÔÏó

* 10.ʹÓÃMessage msg = Message.obtain(),

* 11.ÉèÖÃmsg.whatÊÇint ÀàÐÍÓÃÀ´±íʾ±êʶ

* ·ûÈçSUCCESS,ERROR Óëmsg.objΪObjectÀàÐÍmsg.obj=bitmap,ÓÃÀ´´«µÝÊý¾Ý

* 12.handler.sendMessage(msg)·¢Ë͸øÖ÷Ï̵߳ÄHandler¶ÔÏó

* 13.Ö÷Ïß³ÌÖÐHandler handler = newHandler(){

* ÖØÐ´handleMessage·½·¨ ÅжÏmsg.what,×öÖ÷Ïß³ÌÖеÄUI¸üлòÕßÌáʾÓû§´íÎóÐÅÏ¢

* }

* 14.Ìí¼ÓÍøÂçȨÏÞInternet

public class MainActivity extends Activity {

* ±êʶ ³£Á¿

protected static final int ERROR = 0;

protected static final int SUCCESS = 1;

* Óû§ÊäÈëµÄurlµØÖ·

private EditText et_path;

* ÏÔʾͼƬ

private ImageView iv_show;

* Handler ´¦Àí

private Handler handler;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

* Óû§ÊäÈëµÄurlµØÖ·

et_path = (EditText) findViewById(R.id.et_path);

* ÏÔʾͼƬ

iv_show = (ImageView) findViewById(R.id.iv_show);

* 13.Ö÷Ïß³ÌÖÐHandler handler = newHandler(){

* ÖØÐ´handleMessage·½·¨ ÅжÏmsg.what,×öÖ÷Ïß³ÌÖеÄUI¸üлòÕßÌáʾÓû§´íÎóÐÅÏ¢

* }

handler = new Handler(){

@Override

public void handleMessage(Message msg) {

switch (msg.what) {

case SUCCESS:

iv_show.setImageBitmap((Bitmap)msg.obj);

break;

case ERROR:

Toast.makeText(MainActivity.this, "ÍøÂçÁ¬½Ó³¬Àï", Toast.LENGTH_SHORT).show();

break;

}

}

};

}

* ÏÔʾͼƬµÄ°´¼ü »ñÈ¡Óû§ÊäÈëµÄURL, ²¢ÏÔʾÔÚÏ·½

* @param v

* °´¼üdisplay

public void display(View v) {

// *1.»ñÈ¡ÊäÈëµÄURLµØÖ·,ÅжÏÊÇ·ñΪ¿Õ

final String path = et_path.getText().toString().trim();

if(TextUtils.isEmpty(path)){

Toast.makeText(this, "ÊäÈëµÄurl·¾¶²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();

return ;

}

// * 2.½¨Á¢×ÓÏß³Ì,»ñÈ¡URl¶ÔÏónew URL(path)

new Thread(new Runnable() {

@Override

public void run() {

try {

// * 3.´ò¿ªÁ¬½Ó»ñÈ¡HttpURLConnection conn = (HttpURLConnection)

URL url = new URL(path);

// url.openConnection();

HttpURLConnection conn= (HttpURLConnection) url.openConnection();

// * 4.ÉèÖÃÁ¬½Ó³¬Ê±Ê±¼äconn.setConnectionTimeOut(5000)ºÁÃë

conn.setConnectTimeout(5000);

// * 5.ÉèÖÃÇëÇó·½Ê½setRequestMethod GET»òÕßPOSTÒª´óд

conn.setRequestMethod("GET");

// * 6.»ñÈ¡ÏìÓ¦Âë conn.getResponseCode()

int code = conn.getResponseCode();

// * 7.ÅжÏÊDz»ÊÇ200,ÊÇ200¾ÍÒ»ÇÐÕý³£

if(code==200){

// * 8.»ñÈ¡conn.getInputStream() ,

InputStream in = conn.getInputStream();

// * 9.ʹÓÃBitmapFactory.decodeStream(in),½«Á÷ת»»ÎªBitmap¶ÔÏó

Bitmap bitmap = BitmapFactory.decodeStream(in);

// * 10.ʹÓÃMessage msg = Message.obtain(),

Message msg = Message.obtain();

// * 11.ÉèÖÃmsg.whatÊÇint ÀàÐÍÓÃÀ´±íʾ±êʶ ·ûÈçSUCCESS,ERROR

msg.what=SUCCESS;

// Óëmsg.objΪObjectÀàÐÍmsg.obj=bitmap,ÓÃÀ´´«µÝÊý¾Ý

msg.obj=bitmap;

// * 12.handler.sendMessage(msg)·¢Ë͸øÖ÷Ï̵߳ÄHandler¶ÔÏó

handler.sendMessage(msg);

}else{

sendError();

}

} catch (MalformedURLException e) {

e.printStackTrace();

sendError();

} catch (ProtocolException e) {

e.printStackTrace();

sendError();

} catch (IOException e) {

e.printStackTrace();

sendError();

}

}

private void sendError() {

Message msg = Message.obtain();

// * 11.ÉèÖÃmsg.whatÊÇint ÀàÐÍÓÃÀ´±íʾ±êʶ ·ûÈçSUCCESS,ERROR

msg.what=ERROR;

// * 12.handler.sendMessage(msg)·¢Ë͸øÖ÷Ï̵߳ÄHandler¶ÔÏó

handler.sendMessage(msg);

}

}).start();

}

}

Ìí¼ÓÍøÂçȨÏÞ

<uses-permission android:name="android.permission.INTERNET"/>

2.HTMLView²é¿´

²¼¾Ö

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<!--

Óû§ÊäÈëµÄURL -->

<EditText

android:id="@+id/et_path"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="http://188.188.3.79:8080/"/>

<Button

android:id="@+id/btn_show"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="ÏÔʾ"/>

<ScrollView

android:layout_width="match_parent"

android:layout_height="match_parent">

<!-- ÏÔʾ½á¹û -->

<TextView

android:id="@+id/tv_result"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

</ScrollView>

</LinearLayout>

Á÷ת»»¹¤¾ßÀà


* ½«Á÷ת»»Îª×Ö·ûµÄ¹¤¾ßÀà

public class StreamUtils {

public static String decode(InputStream in) throws IOException {

ByteArrayOutputStream baos = new ByteArrayOutputStream();

int len =0;

byte [] buf = new byte[1024];

while((len=in.read(buf))!=-1){

baos.write(buf, 0, len);

}

in.close();

baos.close();

return baos.toString();

}

}

Activitty

* HTML²é¿´Æ÷

* ²½Öè:

* 1.»ñÈ¡Óû§ÊäÈëµÄurl

* 2.ÅжÏÊÇ·ñΪ¿Õ

* 3.½¨Á¢×ÓÏß³Ì

* 4.½¨Á¢url¶ÔÏó

* 5. ½¨Á¢HttpURLConnectionÁ¬½Ó

* 6.ÉèÖÃÇëÇó·½Ê½,ÓëÁ¬½Ó³¬Ê±

* 7.»ñÈ¡ÏìÓ¦Âë

* 8.ÅжÏÊÇ·ñΪ200

* 9.»ñÈ¡ÊäÈëÁ÷

* 10.½âÎöΪ×Ö·û´®

* 11.handler·¢ËÍmessage

* 12.Ö÷Ïß³ÌÖеÄHandler×ö¸üÐÂUIµÄ²Ù×÷

public class MainActivity extends Activity implements OnClickListener {

protected static final int ERROR = 0;

protected static final int SUCCESS = 1;

* Óû§ÊäÈëµÄURL

private EditText et_path;

* ÊäÈëÍê³Éºóµã»÷µÄ°´¼ü

private Button btn_show;

* ½á¹ûÏÔʾ

private TextView tv_result;

* ÏûÏ¢´¦Àí

private Handler handler;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

* Óû§ÊäÈëµÄURL

et_path = (EditText) findViewById(R.id.et_path);

* ÊäÈëÍê³Éºóµã»÷µÄ°´¼ü

btn_show = (Button) findViewById(R.id.btn_show);

btn_show.setOnClickListener(this);

* ½á¹ûÏÔʾ

tv_result = (TextView) findViewById(R.id.tv_result);

* ÏûÏ¢´¦Àí

handler = new Handler(){

@Override

public void handleMessage(Message msg) {

//ÅжÏmsg.what

switch (msg.what) {

case SUCCESS:

//³É¹¦¾Í´¦ÀíÊý¾Ý

tv_result.setText(msg.obj.toString());

break;

case ERROR:

//ʧ°Ü¾ÍÌáʾÓû§Ê§°Ü

Toast.makeText(MainActivity.this, "ÍøÂçÁ¬½Ó³¬Ê±", Toast.LENGTH_SHORT).show();

break;

}

}

};

}

* µ¥»÷ʼþ¼àÌýÆ÷

@Override

public void onClick(View v) {

switch (v.getId()) {

case R.id.btn_show:

display();

break;

}

}

* ÏÔʾͼƬµÄ·½·¨µ¥»÷ʼþ

private void display() {

//1.»ñÈ¡Óû§ÊäÈëµÄurl

final String path = et_path.getText().toString().trim();

//2.ÅжÏÊÇ·ñΪ¿Õ

if(TextUtils.isEmpty(path)){

Toast.makeText(this, "url²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();

return;

}

//3.½¨Á¢×ÓÏß³Ì

new Thread(new Runnable() {

@Override

public void run() {

try {

//4.½¨Á¢url¶ÔÏó

URL url = new URL(path);

//5. ½¨Á¢HttpURLConnectionÁ¬½Ó

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

//6.ÉèÖÃÇëÇó·½Ê½,ÓëÁ¬½Ó³¬Ê±

conn.setRequestMethod("GET");

conn.setConnectTimeout(5000);

//7.»ñÈ¡ÏìÓ¦Âë

int code = conn.getResponseCode();

//8.ÅжÏÊÇ·ñΪ200

if(code==200){

//9.»ñÈ¡ÊäÈëÁ÷

InputStream in = conn.getInputStream();

//10.½âÎöΪ×Ö·û´®

String data = StreamUtils.decode(in);

//ÊÇ200±íʾ³É¹¦ ÉèÖóɹ¦ÏûÏ¢

Message msg = Message.obtain();

//ÉèÖóɹ¦±êʶ

msg.what=SUCCESS;

//´«µÝÊý¾Ý

msg.obj=data;

//·¢ËÍÏûÏ¢

handler.sendMessage(msg);

}else{

//·¢ËÍ´íÎóÏûÏ¢

sendError();

}

} catch (MalformedURLException e) {

e.printStackTrace();

//·¢ËÍ´íÎóÏûÏ¢

sendError();

} catch (IOException e) {

e.printStackTrace();

//·¢ËÍ´íÎóÏûÏ¢

sendError();

}

}

private void sendError() {

//´íÎó·¢ËÍ´íÎóÏûÏ¢

Message msg = Message.obtain();

//ÉèÖôíÎó±êʶ

msg.what=ERROR;

//·¢ËÍÏûÏ¢

handler.sendMessage(msg);

}

} ).start();

}

}

Ìí¼ÓÍøÂçȨÏÞ

<uses-permission android:name="android.permission.INTERNET"/>

3.ANRÏÖÏó:

Anr( application not responding) ---- Ó¦ÓóÌÐòÎÞÏìÓ¦

Èç¹û µã»÷ÁË Ä³¸ö°´Å¥ ,°´Å¥±³ºó¸ÉÁ˱ȽϺÄʱµÄʶù , ³¤Ê±¼äµÄûÓÐÏàÓ¦, ²¢ÇÒÕâ¸ö³¤Ê±¼äµÄʶùÊÇÔËÐÐÔÚÖ÷Ï̵߳Ä

ÄÇô¾Í »á³öÏÖANRÏÖÏó.

Ö÷Ïß³ÌÖв»ÄÜ¸É ºÄʱµÄʶù, Ö÷Ï̲߳»Äܹ»±»×èÈû.

4. ÊÖ»úºÅÂ뼪ÐײâÊÔ(xmlÊý¾ÝµÄ½âÎö):

ʵÌåÀà

* ½âÎöXML·â×°µÄJAVABEAN

* <phones>

<phone type="huawei">

<phoneNum>13410110407</phoneNum>

<address>¹ã¶«ÉîÛÚÒÆ¶¯</address>

<phoneJx>´óÐ×Ö®Õ×,¶à¶à°ÝÉñ</phoneJx>

</phone>

</phones>


public class Phone {

* ÊÖ»úÀàÐÍ

private String type;

* ÊÖ»ú ºÅÂë

private String phoneNum;

* ¹éÊôµØ

private String address;

* ÊÖ»úºÅ¼ªÐ×

private String phoneJx;

* GetterÓëSetter·½·¨

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public String getPhoneNum() {

return phoneNum;

}

public void setPhoneNum(String phoneNum) {

this.phoneNum = phoneNum;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public String getPhoneJx() {

return phoneJx;

}

public void setPhoneJx(String phoneJx) {

this.phoneJx = phoneJx;

}

public String show(){

return "ÊÖ»úºÅÂë:"+this.phoneNum+",ÊÖ»úÀàÐÍ:"+this.type+",¹éÊôµØ:"+this.address+",ÊÖ»úºÅ¼ªÐ×";

}

}

¹¤¾ßÀà

* XMLÁ÷½âÎö¹¤¾ßÀà

public class StreamUtils {

* »ñÈ¡URLConnectionµÄInputStream

* @param in ÊäÈëÁ÷

* @return ·µ»ØÒ»¸öphone¶ÔÏó

public static Phone decode(InputStream in){

Phone p = new Phone();

try {

XmlPullParser pullParser = Xml.newPullParser();

pullParser.setInput(in,"UTF-8");

int eventType = pullParser.getEventType();

while(eventType!=XmlPullParser.END_DOCUMENT){

if(eventType==XmlPullParser.START_TAG){

if("phone".equals(pullParser.getName())){

String type = pullParser.getAttributeValue(null, "type");

p.setType(type);

}else if("phoneNum".equals(pullParser.getName())){

String phoneNum = pullParser.nextText();

p.setPhoneNum(phoneNum);

}else if("address".equals(pullParser.getName())){

String address = pullParser.nextText();

p.setAddress(address);

}else if("phoneJx".equals(pullParser.getName())){

String phoneJx = pullParser.nextText();

p.setPhoneJx(phoneJx);

}

}

eventType=pullParser.next();

}

in.close();

} catch (XmlPullParserException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return p;

}

}

²¼¾Ö

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<!--Óû§ÊäÈëµÄURL -->

<EditText

android:id="@+id/et_path"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="ÇëÊäÈëURL"

android:text="http://188.188.3.79:8080/itest/phone.xml"/>

<!-- ·¢ËÍ-->

<Button

android:onClick="send"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="ÇëÇó"/>

<TextView

android:id="@+id/tv_result"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

</LinearLayout>

Activity

* ÍøÂçÇëÇóXML

1.»ñÈ¡Óû§ÊäÈëµÄURLµØÖ·

2.ÅжÏÓû§ÊäÈëÊÇ·ñΪ¿Õ,Ϊ¿Õ¾ÍÌáʾÓû§

3.²»Îª¿Õ¾Í´´½¨×ÓÏß³Ì

4.´´½¨URL¶ÔÏónew

* URL(paht)

5.url.openConnection();

* 6.ÉèÖÃÇëÇó·½·¨setRequestMethod("GET"),ÉèÖÃÁ¬½Ó³¬Ê±Ê±¼äsetConnectTimeOut(5000)

* 7.»ñÈ¡ÏìÓ¦Âë,ÅжÏÊÇ·ñΪ200,²»Îª200¾ÍʹÓÃhandler·¢ËÍErrorµÄmessage

* 8.ÊÇ200,¾Í»ñÈ¡ÊäÈëÁ÷conn.getInputStream()

9.ʹÓÃXml.PullParse½âÎöxml,²¢·âװΪ¶ÔÏó,·µ»ØÒ»¸ö¶ÔÏó

* 10.ʹÓÃhandler·¢ËÍmessage,messag.what=SUCCESS,message.obj=·â×°µÄ¶ÔÏó

* 11.Ö÷Ïß³ÌhandlerÖØÐ´handlMessage·½·¨,ÅжÏmsg.what Ö´ÐиüÐÂUIÐÅÏ¢»òÕßÌáʾÓû§´íÎóÐÅÏ¢

public class MainActivity extends Activity {

* ±êʶ·û³£Á¿

protected static final int SUCCESS = 0;

protected static final int ERROR = 1;

* Óû§ÊäÈëµÄURL

private EditText et_path;

* ÏÔʾ½á¹û

private TextView tv_result;

private Handler handler;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

et_path = (EditText) findViewById(R.id.et_path);

tv_result = (TextView) findViewById(R.id.tv_result);

handler = new Handler() {

@Override

public void handleMessage(Message msg) {

// 11.Ö÷Ïß³ÌhandlerÖØÐ´handlMessage·½·¨,ÅжÏmsg.what Ö´ÐиüÐÂUIÐÅÏ¢»òÕßÌáʾÓû§´íÎóÐÅÏ¢

switch (msg.what) {

case SUCCESS:

Phone phone = (Phone) msg.obj;

tv_result.setText(phone.show());

break;

case ERROR:

Toast.makeText(MainActivity.this, "ÍøÂçÒì³£",

Toast.LENGTH_SHORT).show();

break;

}

}

};

}

* ·¢ËÍÓû§ÊäÈëµÄURL,»ñÈ¡XMLÊý¾Ý

* @param v

public void send(View v) {

// 1.»ñÈ¡Óû§ÊäÈëµÄURLµØÖ·

final String path = et_path.getText().toString().trim();

// 2.ÅжÏÓû§ÊäÈëÊÇ·ñΪ¿Õ,Ϊ¿Õ¾ÍÌáʾÓû§

if (TextUtils.isEmpty(path)) {

Toast.makeText(this, "urlµØÖ·²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();

return;

}

// 3.²»Îª¿Õ¾Í´´½¨×ÓÏß³Ì

new Thread(new Runnable() {

@Override

public void run() {

try {

// 4.´´½¨URL¶ÔÏónew URL(path)

URL url = new URL(path);

// 5.url.openConnection();

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

// 6.ÉèÖÃÇëÇó·½·¨setRequestMethod("GET"),ÉèÖÃÁ¬½Ó³¬Ê±Ê±¼äsetConnectTimeOut(5000)

conn.setRequestMethod("GET");

conn.setConnectTimeout(5000);

// 7.»ñÈ¡ÏìÓ¦Âë,ÅжÏÊÇ·ñΪ200,²»Îª200¾ÍʹÓÃhandler·¢ËÍErrorµÄmessage

int code = conn.getResponseCode();

if(code==200){

// 8.ÊÇ200,¾Í»ñÈ¡ÊäÈëÁ÷conn.getInputStream()

InputStream in = conn.getInputStream();

// 9.ʹÓÃXml.PullParse½âÎöxml,²¢·âװΪ¶ÔÏó,·µ»ØÒ»¸ö¶ÔÏó

Phone phone = StreamUtils.decode(in);

// 10.ʹÓÃhandler·¢ËÍmessage,messag.what=SUCCESS,message.obj=·â×°µÄ¶ÔÏó

Message msg = Message.obtain();

msg.what=SUCCESS;

msg.obj = phone;

handler.sendMessage(msg);

}else{

//·¢ËÍ´íÎóÏûÏ¢

sendErrorMessage();

}

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (ProtocolException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

* ·¢Ë͵ÄÏûÏ¢

private void sendErrorMessage() {

Message msg = Message.obtain();

msg.what=ERROR;

handler.sendMessage(msg);

}

}).start();

}

}

5.½âÎöJSON

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:orientation="vertical" >

<EditText

android:id="@+id/et_city"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="ÇëÊäÈëÒª²éѰµÄ³ÇÃû³Æ"/>

<Button

android:onClick="search"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="²éѯÌìÆø"/>

<TextView

android:id="@+id/tv_result"

android:gravity="center_horizontal"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

<ListView

android:id="@+id/lv"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:divider="#ff0000"

android:dividerHeight="2dp">

</ListView>

</LinearLayout>

weather_ithem

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

<TextView

android:id="@+id/fengxiang"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:id="@+id/fengli"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:id="@+id/high"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:id="@+id/type"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:id="@+id/low"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:id="@+id/date"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

</LinearLayout>

¹¤¾ßÀà

/**

* ½âÎöÁ÷µÄ¹¤¾ßÀà,

* °ÑÁ÷½âÎöΪ×Ö·û´®

public class StreamUtils {

public static String decode(InputStream in) throws IOException {

ByteArrayOutputStream baos = new ByteArrayOutputStream();

int len =0;

byte [] buff = new byte[1024];

while((len=in.read(buff))!=-1){

baos.write(buff, 0, len);

}

in.close();

baos.close();

return baos.toString();

}

}

Activity


* ²éѯÌìÆøÔ¤±¨

* 1.»ñÈ¡ÊäÈëµÄ³ÇÊÐ

* 2.ÅжÏÊÇ·ñΪ¿Õ

* 3.»ñÈ¡stringÖеÄ×ÊÔ´ÓëÓû§ÊäÈëµÄÆ´½ÓΪ·ÃÎʵÄurl

* 4.½¨Á¢HttpURLConnection

* 5.ÉèÖÃÇëÇó·½Ê½ÓëÁ¬½Ó³¬Ê±Ê±¼ä

* 6.»ñÈ¡ÏìÓ¦Âë

* 7.ÅжÏÊÇ·ñΪ200

* 8.ÊÇ200¾Í,ʹÓÃ×Ô¶¨ÒåµÄÁ÷¹¤¾ßÀà,½«Á÷ת»»Îª×Ö·û´®

* 9.»ñÈ¡DESCÅжÏÊÇ·ñΪOK,·Ö±ð´¦Àí

* 10,ÊÇOK,¼ÌÐøÊ¹ÓÃJSON½âÎö

* 11.½«Êý×é·¢¸øÖ÷Ïß³ÌÖеÄhandler×ö´¦Àí

* 12.handler×ö¸üÐÂUI»òÕß ÌáʾÓû§´íÎóÐÅÏ¢µÈ

public class MainActivity extends Activity {

protected static final int SUCCESS = 0;

protected static final int INVALID_CITY = 1;

protected static final int ERROR = 2;

private static final String TAG = "R.string.weather";

* Óû§ÊäÈëµÄ³ÇÊÐ

private EditText et_city;

* ÈÝÆ÷ÓÃÓÚÏÔʾ½á¹û

private ListView lv;

private TextView tv_result;

private BaseAdapter adapter;

* handler

private Handler handler;

private ProgressDialog dialog;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

et_city = (EditText) findViewById(R.id.et_city);

lv = (ListView) findViewById(R.id.lv);

tv_result = (TextView) findViewById(R.id.tv_result);

handler = new Handler(){

@Override

public void handleMessage(Message msg) {

switch (msg.what) {

case SUCCESS:

final JSONArray array =(JSONArray) msg.obj;

//tv_result.setText(array.toString());

adapter = new BaseAdapter() {

@Override

public View getView(int position, View convertView, ViewGroup parent) {

View view ;

if(convertView==null){

view = View.inflate(MainActivity.this, R.layout.weather_item, null);

}else{

view = convertView;

}

try {

JSONObject obj = array.getJSONObject(position);

TextView fengxiang =(TextView) view.findViewById(R.id.fengxiang);

fengxiang.setText("·çÏò:"+obj.getString("fengxiang"));

TextView fengli =(TextView) view.findViewById(R.id.fengli);

fengli.setText("·çÁ¦:"+obj.getString("fengli"));

TextView high =(TextView) view.findViewById(R.id.high);

high.setText("¸ßÎÂ:"+obj.getString("high"));

TextView type =(TextView) view.findViewById(R.id.type);

type.setText("ÌìÆø:"+obj.getString("type"));

TextView low =(TextView) view.findViewById(R.id.low);

low.setText("µÍÎÂ:"+obj.getString("low"));

TextView data =(TextView) view.findViewById(R.id.date);

data.setText("ÈÕÆÚ:"+obj.getString("data"));

} catch (JSONException e) {

e.printStackTrace();

}

return view;

}

@Override

public long getItemId(int position) {

// TODO Auto-generated method stub

return position;

}

@Override

public Object getItem(int position) {

// TODO Auto-generated method stub

return position;

}

@Override

public int getCount() {

// TODO Auto-generated method stub

return array.length();

}

};

dialog.dismiss();

lv.setAdapter(adapter);

break;

case ERROR:

Toast.makeText(MainActivity.this, "ÍøÂçÒì³£", Toast.LENGTH_SHORT).show();

break;

case INVALID_CITY:

Toast.makeText(MainActivity.this, "ÊäÈëµÄ³ÇÊÐ ²»´æÔÚ", Toast.LENGTH_SHORT).show();

break;

}

}

};

}

* ²éѯÌìÆø

* @param v ²éѯ°´¼ü

public void search(View v){

//»ñÈ¡Óû§»¯ÊäÈëµÄ³ÇÊÐ

final String city = et_city.getText().toString().trim();

if(TextUtils.isEmpty(city)){

Toast.makeText(this, "³ÇÊв»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();

return;

}

System.out.println(city);

dialog = ProgressDialog.show(MainActivity.this, "ŬÁ¦¼ÓÔØ", "ÇëÉÔºó..........");

new Thread(new Runnable() {

@Override

public void run() {

try {

//ÇëÇó·¾¶

String path=getResources().getString(R.string.weather);

Log.i(TAG, path);

//½¨Á¢URL

URL url = new URL(path+URLEncoder.encode(city, "UTF-8"));

//´ò¿ªÁ¬½Ó

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

//ÉèÖÃÖ÷Çó·½Ê½ÓëÁ¬½Ó³¬Ê±Ê±¼ä

conn.setRequestMethod("GET");

conn.setConnectTimeout(5000);

//»ñÈ¡ÏìÓ¦Âë

int code = conn.getResponseCode();

//ÅжÏÊÇ·ñΪ³É¹¦

if(code==200){

//»ñÈ¡ÊäÈëÁ÷

InputStream in = conn.getInputStream();

String data = StreamUtils.decode(in);

JSONObject dataObj = new JSONObject(data);

String desc = dataObj.getString("desc");

Log.i(TAG, desc);

if("ok".equalsIgnoreCase(desc)){

/**

* {"desc":"OK",

* "status":1000,

* "data":{"wendu":"13","ganmao":"ÌìÆø½ÏÁ¹£¬½ÏÒ×·¢Éú¸Ðð£¬ÇëÊʵ±Ôö¼ÓÒ·þ¡£ÌåÖʽÏÈõµÄÅóÓÑÓÈÆäÓ¦¸Ã×¢Òâ·À»¤¡£",

* "forecast":

* [{"fengxiang":"ÎÞ³ÖÐø·çÏò","fengli":"΢·ç¼¶","high":"¸ßΠ15¡æ","type":"СÓê","low":"µÍΠ11¡æ","date":"23ÈÕÐÇÆÚ¶þ"},

* {"fengxiang":"ÎÞ³ÖÐø·çÏò","fengli":"΢·ç¼¶","high":"¸ßΠ15¡æ","type":"Òõ","low":"µÍΠ12¡æ","date":"24ÈÕÐÇÆÚÈý"},

* {"fengxiang":"ÎÞ³ÖÐø·çÏò","fengli":"΢·ç¼¶","high":"¸ßΠ16¡æ","type":"СÓê","low":"µÍΠ12¡æ","date":"25ÈÕÐÇÆÚËÄ"},

* {"fengxiang":"ÎÞ³ÖÐø·çÏò","fengli":"΢·ç¼¶","high":"¸ßΠ17¡æ","type":"Òõ","low":"µÍΠ13¡æ","date":"26ÈÕÐÇÆÚÎå"},

* {"fengxiang":"ÎÞ³ÖÐø·çÏò","fengli":"΢·ç¼¶","high":"¸ßΠ18¡æ","type":"Òõ","low":"µÍΠ13¡æ","date":"27ÈÕÐÇÆÚÁù"}],

* "yesterday":{"fl":"΢·ç","fx":"ÎÞ³ÖÐø·çÏò","high":"¸ßΠ21¡æ","type":"¶àÔÆ","low":"µÍΠ16¡æ","date":"22ÈÕÐÇÆÚÒ»"},"aqi":"28","city":"ÉîÛÚ"}}

*/

//»ñÈ¡data:ÿһÌìµÄÐÅÏ¢

JSONObject dataJsonObject = dataObj.getJSONObject("data");

//»ñȡһÖܵÄÊý¾Ý

JSONArray array = dataJsonObject.getJSONArray("forecast");

Message msg =Message.obtain();

msg.what =SUCCESS;

msg.obj = array;

handler.sendMessage(msg);

}else {

Message msg = Message.obtain();

msg.what= INVALID_CITY;

handler.sendMessage(msg);

}

}else{

//ÍøÂçÒì³£

sendErrorMessage();

}

} catch (MalformedURLException e) {

e.printStackTrace();

sendErrorMessage();

//ÍøÂçÒì³£

} catch (IOException e) {

e.printStackTrace();

//ÍøÂçÒì³£

sendErrorMessage();

} catch (JSONException e) {

e.printStackTrace();

}

}

//·¢ËÍ´íÎóÐÅÏ¢

private void sendErrorMessage() {

Message msg = Message.obtain();

msg.what= ERROR;

handler.sendMessage(msg);

}

}).start();

}

}

6.Ä£ÄâÐÂÎſͻ§¶Ë

±¾µØtomcat·þÎñÆ÷Ìṩһ¸öXMLÎļþÓëͼƬ

<?xml version="1.0" encoding="UTF-8" ?> 
<channel>
<item>
<title>¾ü±¨ÆÀÐì²Åºñ</title>
<description>ÈËËÀÕ˲»Ïû ·´¸¯²½²»Í££¬Ö§³Ö£¬ÍþÎ䣬¶¥£¬ÓÐÏ£ÍûÁË¡£
</description>
<image>http://192.168.1.104:8080/img/a.jpg</image>
<type>1</type>
<comment>163</comment>
</item>
<item>
<title>Ů˾»ú·­³µºóÖ±±¼Â齫ÊÒ</title>
<description>Ů˾»ú·­³µºóÖ±±¼Â齫ÊÒ£¬³Æ´óÄѲ»ËÀÊÖÆø±Øºì
</description>
<image>http://192.168.1.104:8080/img/b.jpg</image>
<type>2</type>
</item>
<item>
<title>С»ïµ±¡°Äй«¹Ø¡±ÒÔΪÅãÃÀÅ®</title>
<description>À´Ô´£ºÖйúÇàÄêÍø£¬Ð¡»ïµ±¡°Äй«¹Ø¡±ÒÔΪÅãÃÀÅ®£¬ÉϹ¤ºó±»´óÂèÏÅÅ </description>
<image>http://192.168.1.104:8080/img/c.jpg</image>
<type>3</type>
</item>
<item>
<title>ÄÐ×Ó¿´ÉÏÅ®º¢±³Ó°ÓûÇ¿¼é</title>
<description> À´Ô´£ºÐ¾©±¨£¬ ¿´µ½ÕýÁ³ºó·ÅÆúÈÔ±»²¶
</description>
<image>http://192.168.1.104:8080/img/d.jpg</image>
<type>1</type>
<comment>763</comment>
</item>
</channel>

Ìí¼ÓȨÏÞ

<uses-permission android:name="android.permission.INTERNET"/>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">

<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>

</LinearLayout>
//listViewʹÓõÄ
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!--×Ô¶¨ÒåµÄ¿Ø¼þ -->
<com.itheima.newsclient.smartview.MySmartView
android:id="@+id/iv_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_launcher" />

<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/iv_icon"
android:text="±êÌâ" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_below="@id/tv_title"
android:layout_toRightOf="@id/iv_icon"
android:text="ÄÚÈÝÃèÊö" />

<TextView
android:id="@+id/tv_comm"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_below="@id/tv_desc"
android:text="ÆÀÂÛÊý" />
</RelativeLayout>

ʵÌåJAVABEAN

/**
* ÐÂÎÅ·â×°Àà
* <item>
<title>¾ü±¨ÆÀÐì²Åºñ</title>
<description>ÈËËÀÕ˲»Ïû ·´¸¯²½²»Í££¬Ö§³Ö£¬ÍþÎ䣬¶¥£¬ÓÐÏ£ÍûÁË¡£</description>
<image>http://188.188.3.100:8080/img/a.jpg</image>
<type>1</type>
<comment>163</comment>
</item>
*/
public class NewsItems {
private String title;
private String description;
private String imageUrl;
private String type;
private String comment;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getImageUrl() {
return imageUrl;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}
}

¹¤¾ßÀà

/**
* ½âÎöXML
public class NewsClientService {

public static List<NewsItems> getNewsInfo(InputStream in) throws XmlPullParserException, IOException {
List<NewsItems> list = new ArrayList<NewsItems>();
//XML½âÎöÆ÷
XmlPullParser pullParser = Xml.newPullParser();
//ÉèÖÃÊäÈë±àÂë
pullParser.setInput(in,"UTF-8");

//»ñȡʼþ
int eventType = pullParser.getEventType();

//¿ªÊ¼½âÎö
NewsItems newsItem=null;
while(eventType!=XmlPullParser.END_DOCUMENT){

if(eventType==XmlPullParser.START_TAG){
if("item".equals(pullParser.getName())){
//Èç¹ûÊÇ¿ªÊ¼¾ÍжÔÏó
newsItem = new NewsItems();
}else if("title".equals(pullParser.getName())){
//ÉèÖñêÌâ
newsItem.setTitle(pullParser.nextText());
}else if("description".equals(pullParser.getName())){
//ÉèÖÃÃèÊöÄÚÈÝ
newsItem.setDescription(pullParser.nextText());
}else if("image".equals(pullParser.getName())){
//ÉèÖÃimage
newsItem.setImageUrl(pullParser.nextText());

}else if("type".equals(pullParser.getName())){
//ÉèÖÃÀàÐÍ
newsItem.setType(pullParser.nextText());
}else if("comment".equals(pullParser.getName())){
//ÉèÖÃÆÀÂÛÊý
newsItem.setComment(pullParser.nextText());
}


}else if(eventType==XmlPullParser.END_TAG){
if("item".equals(pullParser.getName())){
//Ìí¼Ó¶ÔÏóµ½¼¯ºÏ
list.add(newsItem);
}
}

//ÒÆ¶¯Ö¸Õë
eventType=pullParser.next();
}
return list;
}

}

×Ô¶¨ÒåµÄ

/**
* ×Ô¶¨ÒåÏÔʾµØÖ·ÎªpathµÄͼƬ
public class MySmartView extends ImageView {

public MySmartView(Context context) {
super(context);
}

public MySmartView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public MySmartView(Context context, AttributeSet attrs) {
super(context, attrs);
}
* ÉèÖÃͼÏñ
public void setImage(String url){
ViewAsyncTask viewAsyncTask = new ViewAsyncTask(getContext());

try {
viewAsyncTask.execute(new URL(url));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
private class ViewAsyncTask extends AsyncTask<URL, Integer, Bitmap>{
private Context mContext;
public ViewAsyncTask(Context mContext){
this.mContext=mContext;
}

@Override
protected Bitmap doInBackground(URL... params) {

try {
HttpURLConnection conn = (HttpURLConnection) params[0].openConnection();
//ÉèÖÃÇëÇó·½·¨
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
int code = conn.getResponseCode();
if(code==200){
InputStream in = conn.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(in);
return bitmap;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;

}

@Override
protected void onPostExecute(Bitmap result) {
setImageBitmap(result);
}
}
}

Activity

/**
* Ä£ÄâÐÂÎſͻ§¶Ë 1.
public class MainActivity extends Activity {

private ListView lv;

private List<NewsItems> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

lv = (ListView) findViewById(R.id.lv);

NewsAsyncTask newsAsyncTask = new NewsAsyncTask(this);
try {
newsAsyncTask.execute(new URL(getResources().getString(R.string.path)));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
}

}

private class NewsAsyncTask extends AsyncTask<URL, Integer, List<NewsItems>>{
private List<NewsItems> list = null ;
//¶Ô»°¿ò
private ProgressDialog pDialog;
//ÉÏÏÂÎÄ
private Context mContext;
//¹¹Ô캯Êý
public NewsAsyncTask(Context mContext){
this.mContext = mContext;
}

@Override
protected List<NewsItems> doInBackground(URL... params) {

try {

//»ñÈ¡Á¬½Ó
HttpURLConnection conn = (HttpURLConnection) params[0].openConnection();

//ÉèÖÃÁ¬½ÓÁ¬½Ó·½·¨
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
//»ñÈ¡ÏìÓ¦Âë
int code = conn.getResponseCode();
if(code == 200){
//»ñÈ¡ÊäÈëÁ÷
InputStream in = conn.getInputStream();
//½âÎöXML
list=NewsClientService.getNewsInfo(in);
}
return list;
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(List<NewsItems> result) {
lv.setAdapter(new MyBaseAdapter(result));
//ÉèÖöԻ°¿òÏûʧ
pDialog.dismiss();

}

@Override
protected void onPreExecute() {
//³õʼ»¯¶ÔÏó»°½ø¶ÈÌõ
pDialog = new ProgressDialog(MainActivity.this);
//ÉèÖñêÌâ
pDialog.setTitle("ÐÂÎżÓÔØÖÐ");
//ÉèÖÃÄÚÈÝ
pDialog.setMessage("ÕýÔÚ¼ÓÔØÖÐ........¾ªÏ²ÉÔºó³ÊÏÖ");
//ÉèÖÃÊÇ·ñ¿ÉÒÔÈ¡Ïû true¿ÉÒÔÈ¡Ïû
pDialog.setIndeterminate(true);
//ÉèÖ÷ç¸ñ
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//ÉèÖÃ×î´ó½ø¶È
pDialog.setMax(100);
//ÏÔʾ
pDialog.show();
}

@Override
protected void onProgressUpdate(Integer... values) {
//ÉèÖÃʱ¶È
pDialog.setProgress(values[0]);

}

}

* ListView ÊÊÅäÆ÷
private class MyBaseAdapter extends BaseAdapter {
private static final String TAG = "MyBaseAdapter";
private List<NewsItems> list ;
public MyBaseAdapter(List<NewsItems> list){
this.list=list;
}

@Override
public int getCount() {
return list.size();
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

NewsItems newsItems = list.get(position);
Log.i(TAG, newsItems.getTitle());
View view;
if(convertView==null){
view = View.inflate(MainActivity.this, R.layout.news_items, null);
}else{
view = convertView;
}
//ͼƬ
com.itheima.newsclient.smartview.MySmartView iv_icon =(com.itheima.newsclient.smartview.MySmartView) view.findViewById(R.id.iv_icon);

iv_icon.setImage(newsItems.getImageUrl());

//±êÌâ
TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
tv_title.setText(newsItems.getTitle());
//ÃèÊö
TextView tv_desc = (TextView) view.findViewById(R.id.tv_desc);
tv_desc.setText(newsItems.getDescription());
//ÆÀÂÛ
TextView tv_comm = (TextView) view.findViewById(R.id.tv_comm);

String type = newsItems.getType();

if(type.equals("1")){
tv_comm.setBackgroundColor(Color.RED);
tv_comm.setText("¾ü±¨"+newsItems.getComment());
}else if(type.equals("2")){
tv_comm.setBackgroundColor(Color.BLUE);
tv_comm.setText("ʵʱ"+newsItems.getComment());
}else if(type.equals("3")){
tv_comm.setBackgroundColor(Color.GREEN);
tv_comm.setText("ÓéÀÖ"+newsItems.getComment());
}else if(type.equals("4")){
tv_comm.setBackgroundColor(Color.GRAY);
tv_comm.setText("Éú»î"+newsItems.getComment());
}

return view;
}

}
}

7.Ô´ÉúGETÓëPOSTÇëÇó

±¾µØTOMCATÔËÐзþÎñ¶ËдÁËÒ»¸öServlet

/**
* LoginServlet
* @Decription ´¦ÀíµÇ¼ÇëÇóµÄServlet
@WebServlet(urlPatterns={"/login"})
public class LoginServlet extends HttpServlet {

@SuppressWarnings("deprecation")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/*
* »ñÈ¡Óû§ÃûÓëÃÜÂ벢ת»»ÎªUTF-8
*/
String user = request.getParameter("username");
/*String encode = URLEncoder.encode(user,"iso8859-1");
String decode = URLDecoder.decode(encode, "UTF-8");*/
System.out.println("================get===============");
String username =new String(user.getBytes("iso8859-1"),"utf-8");
System.out.println("getÓû§Ãû:"+username);

String pwd=request.getParameter("password");

String password = new String(pwd.getBytes("iso8859-1"), "UTF-8");
System.out.println("getÃÜÂë:"+password);

/*
* ÕâÀïдËÀÓû§ÃûÓëÃÜÂë,
* Õý³£ÊÇÈ¥Êý¾Ý¿â²éѯ
*/
PrintWriter writer = response.getWriter();

if("admin".equals(username)&& "admin".equals(password)){
writer.write("SUCCESS");

}else{
writer.write("FAILURE");
}
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("================post===============");
request.setCharacterEncoding("UTF-8");
String username = request.getParameter("username");

String password = request.getParameter("password");
System.out.println("post username:"+username+",password: "+password);

if("admin".equals(username) && "admin".equals(password)){
response.getWriter().print("SUCCESS");
}else{
response.getWriter().print("failure");
}
}

}

¹¤¾ßÀà

public class StreamUtils {

public static String decode(InputStream in) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len=0;
byte [] buf = new byte[1024];
while((len=in.read(buf))!=-1){
baos.write(buf, 0, len);
}
in.close();
baos.close();
return baos.toString();
}

}

²¼¾Ö

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/qq"/>

<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ÇëÊäÈëµÇ¼Óû§Ãû"/>
<EditText
android:id="@+id/et_pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="ÇëÊäÈëÃÜÂë"/>

<Button
android:onClick="login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="怬"/>
<TextView
android:id="@+id/tv_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

Activity

public class MainActivity extends Activity {
protected static final int ERROR = 0;
protected static final int SUCCESS = 1;
* Óû§Ãû
private EditText et_name;
* ÃÜÂë
private EditText et_pwd;
* ½á¹û
private TextView tv_result;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

et_name = (EditText) findViewById(R.id.et_name);
et_pwd = (EditText) findViewById(R.id.et_pwd);

tv_result = (TextView) findViewById(R.id.tv_result);
}

private Handler handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case SUCCESS:
tv_result.setText(msg.obj.toString());
break;
case ERROR:
Toast.makeText(MainActivity.this, "ÍøÂçÒì³£", Toast.LENGTH_SHORT).show();
break;

}
};
};
* µÇ¼µã»÷ʼþ
* @param v
* °´¼ü
public void login(View v) {

final String username = et_name.getText().toString().trim();
final String password = et_pwd.getText().toString().trim();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
Toast.makeText(this, "Óû§Ãû»òÕßÃÜÂë²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();
return;
}

new Thread() {
public void run() {
String path = getResources().getString(R.string.path);
try {
path = path + "?username="
+ URLEncoder.encode(username, "UTF-8")
+ "&password="
+ URLEncoder.encode(password, "UTF-8");
//½¨Á¢Á¬½Ó
URL url = new URL(path);

//´ò¿ªÁ¬½Ó
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//ÉèÖÃÇëÇó·½Ê½ÓëÁ¬½Ó³¬Ê±Ê±¼ä
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);

//»ñÈ¡ÏìÓ¦Âë
int code = conn.getResponseCode();
//ÅжÏÏìÓ¦Òì³£
if(code==200){
//»ñÈ¡ÊäÈë
InputStream in = conn.getInputStream();
//½âÎö
String result=StreamUtils.decode(in);
//ÉèÖÃÏûÏ¢
Message msg= Message.obtain();
msg.what=SUCCESS;
msg.obj=result;
//·¢ËÍÏûÏ¢
handler.sendMessage(msg);

}else{
sendErrorMessage();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
sendErrorMessage();
} catch (IOException e) {
e.printStackTrace();
sendErrorMessage();
}

}

private void sendErrorMessage() {
//ÉèÖÃÏûÏ¢
Message msg= Message.obtain();
msg.what=ERROR;
//·¢ËÍÏûÏ¢
handler.sendMessage(msg);
};

}.start();

}

}

Post

public class MainActivity extends Activity {
protected static final int ERROR = 0;
protected static final int SUCCESS = 1;
* Óû§Ãû
private EditText et_name;
* ÃÜÂë
private EditText et_pwd;

* ½á¹û
*/
private TextView tv_result;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

et_name = (EditText) findViewById(R.id.et_name);
et_pwd = (EditText) findViewById(R.id.et_pwd);

tv_result = (TextView) findViewById(R.id.tv_result);
}

private Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case SUCCESS:
tv_result.setText(msg.obj.toString());
break;
case ERROR:
Toast.makeText(MainActivity.this, "ÍøÂçÒì³£", Toast.LENGTH_SHORT)
.show();
break;

}
};
};
* µÇ¼µã»÷ʼþ
* @param v
* °´¼ü
public void login(View v) {

final String username = et_name.getText().toString().trim();
final String password = et_pwd.getText().toString().trim();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
Toast.makeText(this, "Óû§Ãû»òÕßÃÜÂë²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();
return;
}

new Thread() {
public void run() {
String path = getResources().getString(R.string.path);
try {

String params = "username="
+ URLEncoder.encode(username, "UTF-8")
+ "&password="
+ URLEncoder.encode(password, "UTF-8");
* String params = "username=" + username + "&password=" +
* password;
// ½¨Á¢Á¬½Ó
URL url = new URL(path);

// ´ò¿ªÁ¬½Ó
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
// ÉèÖÃÇëÇó·½Ê½ÓëÁ¬½Ó³¬Ê±Ê±¼ä
conn.setRequestMethod("POST");
conn.setConnectTimeout(5000);
// ÉèÖÃÇëÇóÍ·
// Content-Type: application/x-www-form-urlencoded
// Content-Length: 25
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", params.length()
+ "");

// ÉèÖÃÊä³ö
conn.setDoOutput(true);
// °Ñ²ÎÊýÊä³öµ½·þÎñÆ÷
OutputStream out = conn.getOutputStream();
out.write(params.getBytes());
// »ñÈ¡ÏìÓ¦Âë
int code = conn.getResponseCode();
// ÅжÏÏìÓ¦Òì³£
if (code == 200) {
// »ñÈ¡ÊäÈë
InputStream in = conn.getInputStream();
// ½âÎö
String result = StreamUtils.decode(in);
// ÉèÖÃÏûÏ¢
Message msg = Message.obtain();
msg.what = SUCCESS;
msg.obj = result;
// ·¢ËÍÏûÏ¢
handler.sendMessage(msg);

} else {
sendErrorMessage();
}

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
sendErrorMessage();
} catch (IOException e) {
e.printStackTrace();
sendErrorMessage();
}

}

private void sendErrorMessage() {
// ÉèÖÃÏûÏ¢
Message msg = Message.obtain();
msg.what = ERROR;
// ·¢ËÍÏûÏ¢
handler.sendMessage(msg);
};

}.start();

}

}

8.ʹÓÃApacheµÄHttpClientÍê³É

8.1get

public class MainActivity extends Activity {
protected static final int ERROR = 0;
protected static final int SUCCESS = 1; * Óû§Ãû
private EditText et_name;
* ÃÜÂë
private EditText et_pwd; * ½á¹û
private TextView tv_result;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

et_name = (EditText) findViewById(R.id.et_name);
et_pwd = (EditText) findViewById(R.id.et_pwd);

tv_result = (TextView) findViewById(R.id.tv_result);
}

private Handler handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case SUCCESS:
tv_result.setText(msg.obj.toString());
break;
case ERROR:
Toast.makeText(MainActivity.this, "ÍøÂçÒì³£", Toast.LENGTH_SHORT).show();
break;

}
};
};
* µÇ¼µã»÷ʼþ
* @param v
* °´¼ü
public void login(View v) {

final String username = et_name.getText().toString().trim();
final String password = et_pwd.getText().toString().trim();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
Toast.makeText(this, "Óû§Ãû»òÕßÃÜÂë²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();
return;
}

new Thread() {
public void run() {
String path = getResources().getString(R.string.path);
try {
path = path + "?username="
+ URLEncoder.encode(username, "UTF-8")
+ "&password="
+ URLEncoder.encode(password, "UTF-8");
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(path);
//½¨Á¢»ñÈ¡ÏìÓ¦
HttpResponse response = client.execute(httpGet);
//»ñÈ¡ÏìÓ¦Âë
int code = response.getStatusLine().getStatusCode();
//ÅжÏÏìÓ¦Òì³£
if(code==200){
//»ñÈ¡ÊäÈë
InputStream in = response.getEntity().getContent();
//½âÎö
String result=StreamUtils.decode(in);
//ÉèÖÃÏûÏ¢
Message msg= Message.obtain();
msg.what=SUCCESS;
msg.obj=result;
//·¢ËÍÏûÏ¢
handler.sendMessage(msg);

}else{
sendErrorMessage();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
sendErrorMessage();
} catch (IOException e) {
e.printStackTrace();
sendErrorMessage();
}

}

private void sendErrorMessage() {
//ÉèÖÃÏûÏ¢
Message msg= Message.obtain();
msg.what=ERROR;
//·¢ËÍÏûÏ¢
handler.sendMessage(msg);
};

}.start();

}

}

8.2 post

public class MainActivity extends Activity {
protected static final int ERROR = 0;
protected static final int SUCCESS = 1;
* Óû§Ãû
private EditText et_name;
* ÃÜÂë
private EditText et_pwd;
* ½á¹û
private TextView tv_result;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

et_name = (EditText) findViewById(R.id.et_name);
et_pwd = (EditText) findViewById(R.id.et_pwd);

tv_result = (TextView) findViewById(R.id.tv_result);
}

private Handler handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case SUCCESS:
tv_result.setText(msg.obj.toString());
break;
case ERROR:
Toast.makeText(MainActivity.this, "ÍøÂçÒì³£", Toast.LENGTH_SHORT).show();
break;

}
};
};

/**
* µÇ¼µã»÷ʼþ
*
* @param v
* °´¼ü
*/
public void login(View v) {

final String username = et_name.getText().toString().trim();
final String password = et_pwd.getText().toString().trim();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
Toast.makeText(this, "Óû§Ãû»òÕßÃÜÂë²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();
return;
}

new Thread() {
public void run() {
String path = getResources().getString(R.string.path);
try {
/* String params = "username="
+ URLEncoder.encode(username, "UTF-8")
+ "&password="
+ URLEncoder.encode(password, "UTF-8");*/
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(path);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("username",username));
list.add(new BasicNameValuePair("password",password));
httpPost.setEntity(new UrlEncodedFormEntity(list, "UTF-8"));
//½¨Á¢»ñÈ¡ÏìÓ¦
HttpResponse response = client.execute(httpPost);
//»ñÈ¡ÏìÓ¦Âë
int code = response.getStatusLine().getStatusCode();
//ÅжÏÏìÓ¦Òì³£
if(code==200){
//»ñÈ¡ÊäÈë
InputStream in = response.getEntity().getContent();
//½âÎö
String result=StreamUtils.decode(in);
//ÉèÖÃÏûÏ¢
Message msg= Message.obtain();
msg.what=SUCCESS;
msg.obj=result;
//·¢ËÍÏûÏ¢
handler.sendMessage(msg);
}else{
sendErrorMessage();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
sendErrorMessage();
} catch (IOException e) {
e.printStackTrace();
sendErrorMessage();
}

}

private void sendErrorMessage() {
//ÉèÖÃÏûÏ¢
Message msg= Message.obtain();
msg.what=ERROR;
//·¢ËÍÏûÏ¢
handler.sendMessage(msg);
};

}.start();

}

}

9.ʹÓÿªÔ´µÄ¿ò¼ÜÍê³É

https://github.com/loopj/android-async-http

9.1 get

/**
* µÇ¼µã»÷ʼþ
*
* @param v
* °´¼ü
*/
public void login(View v) {

final String username = et_name.getText().toString().trim();
final String password = et_pwd.getText().toString().trim();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
Toast.makeText(this, "Óû§Ãû»òÕßÃÜÂë²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();
return;
}
String path = getResources().getString(R.string.path);
/* try {
path = path + "?username="
+ URLEncoder.encode(username, "UTF-8")
+ "&password="
+ URLEncoder.encode(password, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}*/
//ʹÓÿªÔ´¿ò¼Ü https://github.com/loopj/android-async-http

AsyncHttpClient httpClient = new AsyncHttpClient();

/* httpClient.get(path, new AsyncHttpResponseHandler() {

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
tv_result.setText("code"+statusCode+"ÏìÓ¦Ìå"+new String(responseBody));

}

@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
tv_result.setText("code"+statusCode+"ÏìÓ¦Ìå"+new String(responseBody));
}
});*/

RequestParams params = new RequestParams();
params.put("username", username);
params.put("password", password);
httpClient.get(path, params, new AsyncHttpResponseHandler() {

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
tv_result.setText("code"+statusCode+"ÏìÓ¦Ìå"+new String(responseBody));

}

@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
tv_result.setText("code"+statusCode+"ÏìÓ¦Ìå"+new String(responseBody));

}
});

}

9.2post

 /**
* µÇ¼µã»÷ʼþ
*
* @param v
* °´¼ü
*/
public void login(View v) {

final String username = et_name.getText().toString().trim();
final String password = et_pwd.getText().toString().trim();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
Toast.makeText(this, "Óû§Ãû»òÕßÃÜÂë²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();
return;
}
String path = getResources().getString(R.string.path);
/* try {
path = path + "?username="
+ URLEncoder.encode(username, "UTF-8")
+ "&password="
+ URLEncoder.encode(password, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}*/

AsyncHttpClient httpClient = new AsyncHttpClient();

/* httpClient.get(path, new AsyncHttpResponseHandler() {

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
tv_result.setText("code"+statusCode+"ÏìÓ¦Ìå"+new String(responseBody));

}

@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
tv_result.setText("code"+statusCode+"ÏìÓ¦Ìå"+new String(responseBody));
}
});*/

RequestParams params = new RequestParams();
params.put("username", username);
params.put("password", password);
httpClient.post(path, params, new AsyncHttpResponseHandler() {

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
tv_result.setText("code"+statusCode+"ÏìÓ¦Ìå"+new String(responseBody));

}

@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
tv_result.setText("code"+statusCode+"ÏìÓ¦Ìå"+new String(responseBody));

}
});

}

10.ʹÓÿªÔ´¿ò¼ÜÉÏ´«Îļþ

·þÎñÆ÷,ʹÓÃServletÍê³ÉʹÓÃApacheµÄcommons-fileupload,commons-ioдµÄÎļþÉÏ´«

public class UploadServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
//ArrayList<String> list=initList();

// »ñÈ¡´ÅÅÌÎļþ¹¤³§
DiskFileItemFactory factory = new DiskFileItemFactory();
// ÉèÖóõʼֵ
setFactory(factory);
/*
* // ÅäÖóõʼ»¯Öµ»º³åÇø factory.setSizeThreshold(1024 * 1024); // ÉèÖûº³å ÇøÎļþ
* String bufPath = getServletContext().getRealPath("/temp");
*
* factory.setRepository(new File(bufPath));
*/
// »ñÈ¡ÉÏ´«¶ÔÏó½âÎöÆ÷
ServletFileUpload upload = new ServletFileUpload(factory);
// ÅÐ¶Ï ÊDz»ÊǶಿ·Ö×é³É
if (!upload.isMultipartContent(request)) {
request.setAttribute("msg", "±íµ¥²»ÊǶಿ·Ö×é³É,²é¿´enctype");
request.getRequestDispatcher("/upload.jsp").forward(request,
response);
return;
}
// ³õʼ»¯
setFileUpload(upload);
// ÉèÖà ×Ö·û±àÂë
/*
* upload.setHeaderEncoding("utf-8"); // ÉèÖõ¥¸öÎļþ´óС
* upload.setFileSizeMax(1024 * 1024 * 5); // ÉèÖÃ×ÜÎļþ´óС
* upload.setSizeMax(1024 * 1024 * 20);
*
* // ÉèÖÃÉÏ´«¼àÌýÆ÷ upload.setProgressListener(new ProgressListener() {
*
* public void update(long pBytesRead, long pContentLength, int
* pItems) { System.out.println("ÒѾ­¶Á:" + pBytesRead + "×ܹ²´óС :" +
* pContentLength + "µÚ" + pItems + "¸ö");
*
* } });
*/

// »ñÈ¡ÇëÇóµÄÁбí
List<FileItem> parseRequest = upload.parseRequest(request);
// ±éÀú
for (FileItem item : parseRequest) {
// ÅÐ¶Ï ÊDz»ÊÇÆÕͨ±íµ¥Êý¾Ý
if (item.isFormField()) {
String fieldname = item.getFieldName();
String fieldValue = item.getString("UTF-8");
System.out.println("±íµ¥:" + fieldname + "," + fieldValue);
} else {
// ÉÏ´«Â·¾¶
String uploadPath = getServletContext().getRealPath(
"/WEB-INF/upload");
// »ñÈ¡ÎļþÃû
String filename = item.getName();
int index=filename.lastIndexOf(".");
String extname=filename.substring(index);
//ÅжÏÉÏ´«µÄÎļþÊÇ·ñÔÚÉÏ´«Áбí ÖÐ
/*if(!list.contains(extname)){
request.setAttribute("msg", "ÎļþÀàÐÍ"+extname+"²»ÔÚÉÏ´«µÄÀàÐÍÖÐ");
request.getRequestDispatcher("/upload.jsp").forward(request,
response);
return;
}*/

// »ñÈ¡ÊäÈëÁ÷
InputStream in = item.getInputStream();
filename = UUID.randomUUID().toString().replace("-", "")
+ "_" + filename;
System.out.println(filename);
String savePath = genera(uploadPath, filename);
System.out.println(savePath);
//ÉÏ´«Îļþ
uploadFile(in,savePath,filename);
//ɾ³ý»º´æ
item.delete();
}
//ÉÏ´«Ê§°ÜµÄ»º³åÒ²Çå³ý
item.delete();
}

} catch (FileUploadBase.FileSizeLimitExceededException e) {
request.setAttribute("msg", "µ¥¸öÎļþ´óС³¬¹ýÏÞÖÆ");
request.getRequestDispatcher("/upload.jsp").forward(request,
response);
return;
} catch (FileUploadBase.SizeLimitExceededException e) {
request.setAttribute("msg", "Îļþ×Ü´óС³¬¹ýÏÞÖÆ");
request.getRequestDispatcher("/upload.jsp").forward(request,response);
return;
} catch (MyException e) {
request.setAttribute("msg", "ÎļþÀàÐͲ»ÕýÈ·");
request.getRequestDispatcher("/upload.jsp").forward(request,
response);
return;
}catch (Exception e) {
e.printStackTrace();
request.setAttribute("msg", "³ö´íÁË");
request.getRequestDispatcher("/upload.jsp").forward(request,
response);
return;
}
request.setAttribute("msg", "ÉÏ´«³É¹¦");
request.getRequestDispatcher("/upload.jsp").forward(request, response);

}
* ³õʼ»¯¿ÉÒÔÉÏ´«µÄÎļþÁбí
* @return
private ArrayList<String> initList() {
ArrayList<String> list=new ArrayList<String>();
list.add(".jpg");
list.add(".rar");
list.add(".txt");
list.add(".png");
return list;
}

/**
* ÉÏ´«Îļþ
* @param in ÊäÈëÁ÷
* @param savePath ±£´æÂ·¾¶
* @param filename ÎļþÃû³Æ
* @throws Exception
*/
private void uploadFile(InputStream in, String savePath, String filename) throws Exception {
File file = new File(savePath, filename);
// ÉèÖÃÊä³öÁ÷
OutputStream out = new FileOutputStream(file);
int len = 0;
byte[] buf = new byte[1024];
while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
}
in.close();
out.close();

}

/**
* ʹÓùþÏ£Öµ,×öÉ¢ÁеÄÎļþĿ¼
*
* @param uploadPath
* @param filename
* @return
*/
private String genera(String uploadPath, String filename) {
System.out.println(uploadPath);
int hashCode = filename.hashCode();
StringBuilder sb = new StringBuilder();
while (hashCode > 0) {
int tmp = hashCode & 0xf;
sb.append("/");
sb.append(tmp + "");
hashCode = hashCode >> 4;
}
System.out.println(sb.toString());
String path = uploadPath + sb.toString();
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
return path;
}

/**
* ¶ÔÏó½âÎöÆ÷½øÐгõʼ»¯
*
* @param upload
*/
private void setFileUpload(ServletFileUpload upload) {
// ÉèÖà ×Ö·û±àÂë
upload.setHeaderEncoding("utf-8");
// ÉèÖõ¥¸öÎļþ´óС
upload.setFileSizeMax(1024 * 1024 * 20);
// ÉèÖÃ×ÜÎļþ´óС
upload.setSizeMax(1024 * 1024 * 100);
// ÉèÖÃÉÏ´«¼àÌýÆ÷
upload.setProgressListener(new ProgressListener() {

public void update(long pBytesRead, long pContentLength, int pItems) {
System.out.println("ÒѾ­¶Á:" + pBytesRead + "×ܹ²´óС :"
+ pContentLength + "µÚ" + pItems + "¸ö");

}
});

}

/**
* Ϊ¹¤³§ÉèÖóõʼֵ
*/
private void setFactory(DiskFileItemFactory factory) {
// ÅäÖóõʼ»¯Öµ»º³åÇø
factory.setSizeThreshold(1024 * 1024);
// ÉèÖûº³å ÇøÎļþ
String bufPath = getServletContext().getRealPath("/temp");

factory.setRepository(new File(bufPath));
}
}

¿Í»§¶Ë

ȨÏÞ

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

²¼¾Ö

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<!-- ÕâÀï°ÑÎļþдËÀÁË -->

<EditText
android:id="@+id/et_file"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ÇëÊäÈëÒªÉÏ´«µÄÎļþ·¾¶"
android:text="/mnt/sdcard/gm.mp3" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="upload"
android:text="ÉÏ´«" />

<ProgressBar
android:id="@+id/pb"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/tv_display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />

</LinearLayout>

Activity

public class MainActivity extends Activity {

protected static final String TAG = "MainActivity";
/*
* ÊäÈëµÄÎļþµØÖ·
*/
private EditText et_file;

/*
* ½ø¶ÈÌõ
*/
private ProgressBar pb;
/*
* ÏÔʾʱ¶ÈÖµ
*/
private TextView tv_display;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

et_file = (EditText) findViewById(R.id.et_file);

pb = (ProgressBar) findViewById(R.id.pb);

tv_display = (TextView) findViewById(R.id.tv_display);
}

/**
* ÉÏ´«Îļþ
*
* @param v
* ÉÏ´«°´¼ü
*/
public void upload(View v) {
//»ñÈ¡ÊäÈëµÄÎļþµØÖ·
String str = et_file.getText().toString().trim();

File file = new File(str);

// ʹÓÿªÔ´¿ò¼Ü µØÖ·https://github.com/wyouflf/xUtils
HttpUtils httpUtils = new HttpUtils();

RequestParams params = new RequestParams();

params.addBodyParameter("file", file);

// »ñÈ¡ÉÏ´«Â·¾¶,дÔÚvalues--stringsÖÐ
String url = "http://192.168.1.104:8080/MyDay11upload/upload";
Log.i(TAG, url);

// ·¢ËÍÎļþ
httpUtils.send(HttpMethod.POST, url, params,
new RequestCallBack<String>() {

@Override
public void onFailure(HttpException error, String msg) {
Toast.makeText(MainActivity.this, "ÉÏ´«Ê§°Ü:=====" + msg,
Toast.LENGTH_SHORT).show();

}

@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
Toast.makeText(MainActivity.this, "ÉÏ´«³É¹¦:=====",
Toast.LENGTH_SHORT).show();
Header[] headers = responseInfo.getAllHeaders();
for (Header header : headers) {
Log.i(TAG, "key:---->" + header.getName()
+ "values---->" + header.getValue());
}
}

@Override
public void onLoading(long total, long current,
boolean isUploading) {
pb.setMax((int) total);
pb.setProgress((int) current);
tv_display.setText("µ±Ç°½ø¶È:"+current+" ×ܽø¶È:"+total);
}

});

}

}

11.AsyncTask

 * ʹÓÃÒì²½ÏÂÔØ
* 1.´´½¨AsyncTaskr×ÓÀà,²¢ÎªÈý¸ö·ºÐͲÎÊýÖ¸¶¨ÀàÐÍ,Èç¹ûij¸ö·ºÐͲÎÊý²»ÐèÒªÖ¸¶¨ÀàÐÍÔò¿ÉÒÔÖ¸¶¨ÎªVoid
* 2.¸ù¾ÝÐèҪʵÏÖAsyncTAskµÄ·½·¨
* doInBackground ÖØÐ´Õâ¸ö·½·¨,ºǫ́Ï߳̽«ÒªÍê³ÉµÄÈÎÎñ, ¸Ã·½·¨¿ÉÒÔµ÷ÓÃpublishProgress(Progresss....values)·½·¨¸üÐÂÈÎÎñµÄ½ø¶È
* onProExecute():¸Ã·½·¨½«ÔÚºǫ́ºÄʱ²Ù×÷ǰ±»µ÷ÓÃ,ͨ³£¸Ã·½·¨, ÓÃÓÚÍê³ÉһЩ³õʼ»¯×¼±¸¹¤×÷,±ÈÈçÔÚ½çÃæÏÔʾ³õʼ»¯½ø¶ÈµÈ
* onPostExcute(Result result) µ±doInBackgroundÍê³ÉÒÔºó,ϵͳ»á×Ô¶¯µ÷ÓÃonPostExecute()·½·¨, ²¢½«doInBackground·½·¨µÄ·µ»ØÖµ´«¸ø¸Ã·½·¨
*
* 3.µ÷ÓÃAsyncTask×ÓÀàµÄʵÀýexecute(Params..params)¿ªÊ¼Ö´ÐкÄʱÈÎÎñ
* ×¢Òâ:
* ±ØÐëÔÚUIÏß³ÌÖд´½¨AsyncTasckµÄʵÀý
* ±ØÐëÔÚUIÏß³ÌÖе÷ÓÃAsyncTaskµÄexecute()·½·¨
* doInBackground,onProExecute,onPostExcute,opProgressUpdate()·½·¨, ²»Ó¦¸ÃÓóÌÐòÔ±´úÂëµ÷ÓÃ,¶øÊÇÓÃAndroidϵͳ¸ºÔðµ÷ÓÃ
* ÿ¸öAsyncTaskÖ»ÄÜÖ´ÐÐÒ»´Î,¶à´Îµ÷Óý«»áÒý·¢Òì³£

/**
* ʹÓÃÒì²½ÏÂÔØ
* 1.´´½¨AsyncTaskr×ÓÀà,²¢ÎªÈý¸ö·ºÐͲÎÊýÖ¸¶¨ÀàÐÍ,Èç¹ûij¸ö·ºÐͲÎÊý²»ÐèÒªÖ¸¶¨ÀàÐÍÔò¿ÉÒÔÖ¸¶¨ÎªVoid
* 2.¸ù¾ÝÐèҪʵÏÖAsyncTAskµÄ·½·¨
* doInBackground ÖØÐ´Õâ¸ö·½·¨,ºǫ́Ï߳̽«ÒªÍê³ÉµÄÈÎÎñ, ¸Ã·½·¨¿ÉÒÔµ÷ÓÃpublishProgress(Progresss....values)·½·¨¸üÐÂÈÎÎñµÄ½ø¶È
* onProExecute():¸Ã·½·¨½«ÔÚºǫ́ºÄʱ²Ù×÷ǰ±»µ÷ÓÃ,ͨ³£¸Ã·½·¨, ÓÃÓÚÍê³ÉһЩ³õʼ»¯×¼±¸¹¤×÷,±ÈÈçÔÚ½çÃæÏÔʾ³õʼ»¯½ø¶ÈµÈ
* onPostExcute(Result result) µ±doInBackgroundÍê³ÉÒÔºó, ϵͳ»á×Ô¶¯µ÷ÓÃonPostExecute()·½·¨,²¢½«doInBackground·½·¨µÄ·µ»ØÖµ´«¸ø¸Ã·½·¨
* 3.µ÷ÓÃAsyncTask×ÓÀàµÄʵÀýexecute(Params..params)¿ªÊ¼Ö´ÐкÄʱÈÎÎñ
* ×¢Òâ:
* ±ØÐëÔÚUIÏß³ÌÖд´½¨AsyncTasckµÄʵÀý
* ±ØÐëÔÚUIÏß³ÌÖе÷ÓÃAsyncTaskµÄexecute()·½·¨
* doInBackground,onProExecute,onPostExcute,opProgressUpdate()·½·¨, ²»Ó¦¸ÃÓóÌÐòÔ±´úÂëµ÷ÓÃ,¶øÊÇÓÃAndroidϵͳ¸ºÔðµ÷ÓÃ
* ÿ¸öAsyncTaskÖ»ÄÜÖ´ÐÐÒ»´Î,¶à´Îµ÷Óý«»áÒý·¢Òì³£
public class MainActivity extends AppCompatActivity {

Óû§ÊäÈëµÄurl
private EditText tv_path;
*ÏÔʾ½á¹û
private TextView tv_show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv_path = (EditText) findViewById(R.id.tv_path);

tv_show = (TextView) findViewById(R.id.tv_show);
}
* ÏìÓ¦°´¼üµã»÷ÏÂÔØÊ¼þ
* @param v µ±Ç°°´¼ü
public void download(View v){

String path = tv_path.getText().toString().trim();

if(TextUtils.isEmpty(path)){

Toast.makeText(this,"ÏÂÔØÂ·¾¶²»ÄÜΪ¿Õ",Toast.LENGTH_SHORT).show();
return;
}

DownloadTask task = new DownloadTask(this);

try {
//¿ªÊ¼Ö´ÐÐ
task.execute(new URL(path));
} catch (MalformedURLException e) {
e.printStackTrace();
}

}
* ¿É±ä²ÎÊý
* µÚÒ»¸ö:param ±íʾ´«ÈëµÄ²ÎÊý
* µÚ¶þ¸ö:progressºǫ́ÈÎÎñ³ÉµÄ½ø¶ÈÖµµÄÀàÐÍ
* µÚÈý¸ö:Result,·µ»ØµÄÀàÐÍ
private class DownloadTask extends AsyncTask<URL,Integer,String>{
ÉÏÏÂÎÄ
private Context mContext;
½ø¶ÈÌõ
private ProgressDialog progressDialog;
¶¨Òå¼Ç¼¶ÁÈ¡µÄÐÐÊý
private int hasRead = 0;

public DownloadTask(Context context) {
this.mContext = context;
}

@Override
protected String doInBackground(URL... params) {

StringBuilder sb = new StringBuilder();

try {
//´ò¿ªÁ¬½Ó
URLConnection conn = params[0].openConnection();

//¿ªÊ¼¶Á¶Á
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));

String line=null;
//¿ªÊ¼¶Á
while((line=br.readLine())!=null){
sb.append(line+"\n");
}
//·µ»Ø½«Òò±»OnPostexecute·½·¨µ÷ÓýÓÊÕ·µ»ØÖµ
return sb.toString();

} catch (IOException e) {
e.printStackTrace();
}

return null;
}
* ³õʼ»¯²Ù×÷
@Override
protected void onPreExecute() {

progressDialog = new ProgressDialog(mContext);
//ÉèÖöԻ°¿ò±êÌâ
progressDialog.setTitle("ÈÎÎñÕýÔÚÖ´ÐÐÖÐ");
//ÉèÖöԻ°ÏÔʾµÄÄÚÈÝ
progressDialog.setMessage("ÈÎÎñÔÚÆ´Ãü¼ÓÔØÖÐ...ÇëÉÔºó......");
//ÉèÖöԻ°¿ò²»ÄÜÓà ȡÏû °´¼ü¹Ø±Õ
progressDialog.setCancelable(false);

//ÉèÖøýø¶ÈÌõ×îÔÚʱ¶ÈÖµ
progressDialog.setMax(100);
//ÉèÖÃʱ¶ÈÌõµÄ·ç¸ñ
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

//ÉèÖÃÊÇ·ñÏÔʾʱ¶ÈÌõ ²»È·¶¨µÄÊÇ·ñÏÔʾtrueΪ²»ÏÔʾ,
progressDialog.setIndeterminate(false);
progressDialog.show();
}

@Override
protected void onProgressUpdate(Integer... values) {
tv_show.setText("ÒѾ­¶ÁÈ¡====" + values[0] + "=====ÐÐ");

progressDialog.setProgress(values[0]);
}
* µ÷Óà doInBackground,²¢½ÓÊÕÆä·µ»ØÖµ
* @param s
@Override
protected void onPostExecute(String s) {
//ÉèÖÃÏÔʾ
tv_show.setText(s);
//½ø¶È¶Ô»°¿òÏûʧ²»¿É¼û

progressDialog.dismiss();
}
}
}

12.¶àÏ̶߳ϵãÏÂÔØ

JAVAʵÏÖ

package com.it.download;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;

import java.net.URL;
* ¶àÏ̶߳ϵãÏÂÔØ,Ðø´«
* @Decription TODO
public class DownTask {

// ÏÂÔØµØÖ·
public static String path = "http://192.168.1.104:8080/itest/gm.mp3";
/*
* Ïß³ÌÊý
*/
public static int threadCount = 5;

/*
* µ±Ç°ÔËÐеÄÏß³ÌÊý
*/
public static int runninThreadCount =threadCount;
public static void main(String[] args) {

// ¿ªÊ¼Á¬½ÓÍøÂç
try {
URL url = new URL(path);
// ´ò¿ªÍøÂçÁ¬½Ó
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// ÉèÖÃÇëÇó·½Ê½ÓëÁ¬½Ó³¬Ê±Ê±¼ä
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
// »ñÈ¡»ñÈ¡Âë
int code = conn.getResponseCode();
if (code == 200) {
int length = conn.getContentLength();
System.out.println("³¤¶È:" + length);
// ÔÚ±¾µØ´´½¨Ò»¸öÓë·þÎñÒ»Ñù´óСµÄÎļþ
String fileName = getFileName(path);
RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
// ÉèÖÃÎļþµÄ´óС
raf.setLength(length);
raf.close();

// ¼ÆËãÿ¸öÏß³ÌÏÂÔØµÄ´óС
int blockSize = length % threadCount == 0 ? length
/ threadCount : length / threadCount + 1;
//
for (int threadId = 0; threadId < threadCount; threadId++) {
// ¼ÆË㿪ʼÏÂÔØµÄλÖÃÓë½áÊøÏÂÔØµÄÎÄÖÃ
int startIndex = threadId * blockSize;
int endIndex = startIndex + blockSize;
if (endIndex >= length) {
endIndex = length;
}
new DownThread(threadId, startIndex, endIndex).start();

}

}

} catch (Exception e) {
e.printStackTrace();
}

}

/**
* »ñÈ¡ÎļþÃû³Æ
*
* @param path
* ·¾¶
* @return ·µ»ØÎļþÃû³Æ
*/
public static String getFileName(String path) {
int index = path.lastIndexOf("/");
return path.substring(index + 1);
}

/**
* ÏÂÔØµÄÏß³Ì
*
* @Decription TODO
private static class DownThread extends Thread {
// Ïß³ÌIP
private int threadId;
// ¿ªÊ¼Î»ÖÃ
private int startIndex;
// ½áÊøÎ»ÖÃ
private int endIndex;
private int currentPosition;

public DownThread(int threadId, int startIndex, int endIndex) {
super();
this.threadId = threadId;
this.startIndex = startIndex;
this.endIndex = endIndex;
this.currentPosition = startIndex;
}

@Override
public void run() {
System.out.println("Ïß³Ì:" + threadId + ",==¿ªÊ¼ÏÂÔØÎ»ÖÃ:" + startIndex
+ "=========>½áÊøÎ»ÖÃ:" + endIndex);

// ¿ªÊ¼Á¬½ÓÍøÂç
try {
URL url = new URL(path);
// ´ò¿ªÁ¬½Ó
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
// ÉèÖÃÇëÇó·½Ê½ÓëÁ¬½Ó³¬Ê±Ê±¼ä
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
// ÉèÖÃÇëÇóÍ·,¶àÏß³ÌÏÂÔØ,Ö»»ñȡһ²¿·ÖÊý¾Ý

String fileName = getFileName(path);
RandomAccessFile rf = new RandomAccessFile(fileName, "rw");

// Ê×ÏÈÈ·ÈÏÓÐûÓÐÏÂÔØ¹ýÄõ½Îļþ
File fFile = new File(threadId + ".position");
// ÅжÏÎļþÊDz»ÊÇ´æÔÚ,´æÔÚ¾Í˵Ã÷ÏÂÔØ¹ý
if (fFile.exists()) {
//¶ÁÈ¡³öÏÂÔØµÄ½ø¶È
BufferedReader br = new BufferedReader(new FileReader(fFile));
String readLine = br.readLine();

currentPosition = Integer.parseInt(readLine);
conn.setRequestProperty("range", "bytes=" + currentPosition
+ "-" + endIndex);

rf.seek(currentPosition);
br.close();
} else {
// ˵Ã÷ûÓÐÏÂÔØ¹ý
conn.setRequestProperty("range", "bytes=" + startIndex
+ "-" + endIndex);

rf.seek(currentPosition);

}

// »ñÈ¡»ñÈ¡Â벿·ÖÊý¾ÝΪ206
int code = conn.getResponseCode();

if (code == 206) {

InputStream in = conn.getInputStream();
// ÉèÖÿªÊ¼Î»ÖÃ

// ¿ªÊ¼Ð´·Å
int len = 0;
byte[] buf = new byte[1024];
while ((len = in.read(buf)) != -1) {
rf.write(buf, 0, len);
// ÓÃÀ´¼Ç¼µ±Ç°µÄÏÂÔØÎ»ÖÃ
currentPosition += len;
RandomAccessFile positionFile = new RandomAccessFile(
threadId + ".position", "rwd");
// дÈëÎļþ ½¨Á¢»º´æ
positionFile.write((currentPosition + "").getBytes());
positionFile.close();
}

rf.close();
in.close();
System.out.println("Ïß³Ì:" + threadId + "ÏÂÔØÍê³ÉÁË");
//°ÑÏÂÔØÍê³ÉµÄÎļþ±ê¼ÇΪÍê³É
File file = new File(threadId+".position");
file.renameTo(new File(threadId+".position.finished"));
synchronized (DownTask.class) {
//Ïß³ÌÊý-1
runninThreadCount--;
if(runninThreadCount<=0){
for(int i=0;i<threadCount;i++){
File delFile = new File(i+".position.finished");
//ɾ³ý
delFile.delete();
}

}
}
}

} catch (Exception e) {
e.printStackTrace();
}
}

}
}

   
2103 ´Îä¯ÀÀ       27
 
Ïà¹ØÎÄÕÂ

ÊÖ»úÈí¼þ²âÊÔÓÃÀýÉè¼ÆÊµ¼ù
ÊÖ»ú¿Í»§¶ËUI²âÊÔ·ÖÎö
iPhoneÏûÏ¢ÍÆËÍ»úÖÆÊµÏÖÓë̽ÌÖ
AndroidÊÖ»ú¿ª·¢£¨Ò»£©
 
Ïà¹ØÎĵµ

Android_UI¹Ù·½Éè¼Æ½Ì³Ì
ÊÖ»ú¿ª·¢Æ½Ì¨½éÉÜ
androidÅÄÕÕ¼°ÉÏ´«¹¦ÄÜ
Android½²ÒåÖÇÄÜÊÖ»ú¿ª·¢
Ïà¹Ø¿Î³Ì

Android¸ß¼¶Òƶ¯Ó¦ÓóÌÐò
Androidϵͳ¿ª·¢
AndroidÓ¦Óÿª·¢
ÊÖ»úÈí¼þ²âÊÔ
×îл¼Æ»®
DeepSeekÔÚÈí¼þ²âÊÔÓ¦ÓÃʵ¼ù 4-12[ÔÚÏß]
DeepSeek´óÄ£ÐÍÓ¦Óÿª·¢Êµ¼ù 4-19[ÔÚÏß]
UAF¼Ü¹¹ÌåϵÓëʵ¼ù 4-11[±±¾©]
AIÖÇÄÜ»¯Èí¼þ²âÊÔ·½·¨Óëʵ¼ù 5-23[ÉϺ£]
»ùÓÚ UML ºÍEA½øÐзÖÎöÉè¼Æ 4-26[±±¾©]
ÒµÎñ¼Ü¹¹Éè¼ÆÓ뽨ģ 4-18[±±¾©]

androidÈË»ú½çÃæÖ¸ÄÏ
AndroidÊÖ»ú¿ª·¢£¨Ò»£©
AndroidÊÖ»ú¿ª·¢£¨¶þ£©
AndroidÊÖ»ú¿ª·¢£¨Èý£©
AndroidÊÖ»ú¿ª·¢£¨ËÄ£©
iPhoneÏûÏ¢ÍÆËÍ»úÖÆÊµÏÖ̽ÌÖ
ÊÖ»úÈí¼þ²âÊÔÓÃÀýÉè¼ÆÊµ¼ù
ÊÖ»ú¿Í»§¶ËUI²âÊÔ·ÖÎö
ÊÖ»úÈí¼þ×Ô¶¯»¯²âÊÔÑо¿±¨¸æ

Android¸ß¼¶Òƶ¯Ó¦ÓóÌÐò
AndroidÓ¦Óÿª·¢
Androidϵͳ¿ª·¢
ÊÖ»úÈí¼þ²âÊÔ
ǶÈëʽÈí¼þ²âÊÔ
AndroidÈí¡¢Ó²¡¢ÔÆÕûºÏ

ÁìÏÈIT¹«Ë¾ android¿ª·¢Æ½Ì¨×î¼Ñʵ¼ù
±±¾© Android¿ª·¢¼¼Êõ½ø½×
ijÐÂÄÜÔ´ÁìÓòÆóÒµ Android¿ª·¢¼¼Êõ
ijº½Ì칫˾ Android¡¢IOSÓ¦ÓÃÈí¼þ¿ª·¢
°¢¶û¿¨ÌØ LinuxÄÚºËÇý¶¯
°¬Ä¬Éú ǶÈëʽÈí¼þ¼Ü¹¹Éè¼Æ
Î÷ÃÅ×Ó Ç¶Èëʽ¼Ü¹¹Éè¼Æ