ºÎ»ê21±â
¾ÛÅøÁî
46.¢½.168.138
46.¢½.168.129
46.¢½.168.161
46.¢½.168.136
46.¢½.168.145
46.¢½.168.162
46.¢½.168.144
46.¢½.168.140
115.¢½.135.198
46.¢½.168.139
 

[ ºÎ»ê21±â ½ºÅ͵ð ±×·ì]

ÀÏÀÚ : 2016³â12¿ù15ÀÏ~12¿ù27ÀÏ / ½Ã°£ : ¿ÀÈÄ 7½Ã~10½Ã (»óȲ¿¡ µû¶ó º¯µ¿µÉ ¼ö ÀÖÀ¸´Ï °øÁö Çʵ¶)
¸àƼ : ¹èÀÎȯ, °û±Ç¼·, ¼­¿¹¸²
¸àÅä : ÀÌ°æ¿ë
±³Á¦ : ÇѺû¹Ìµð¾î Android Studio¸¦ È°¿ëÇÑ ¾Èµå·ÎÀ̵å ÇÁ·Î±×·¡¹Ö (Áõº¸ÆÇ)
http://book.naver.com/bookdb/book_detail.nhn?bid=10220519
* Çʼö Áغñ¹°Àº ¾Æ´Õ´Ï´Ù. Ã¥ ³»¿ëÀ¸·Î Áøµµ ³ª°¡Áö ¾Ê½À´Ï´Ù.


°Ô½Ã¹° 10°Ç
   
[ÀÚ·á] À¥¼Ò½º °¡Á®¿À±â
±Û¾´ÀÌ : ÀÌ°æ¿ë ³¯Â¥ : 2016-08-11 (¸ñ) 19:51 Á¶È¸ : 1743

package net.apptools.network;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends AppCompatActivity {
    EditText editText;
    Button button;
    TextView textView;
    Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText) findViewById(R.id.editText);
        button = (Button) findViewById(R.id.button);
        textView = (TextView) findViewById(R.id.textView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RequestThread thread = new RequestThread();
                thread.start();
            }
        });
    }

    class RequestThread extends Thread {
        public void run() {
            //ÀÔ·Â »óÀÚ¿¡ ÀÔ·ÂµÈ URLÀ» °¡Á®¿È
            String urlStr = editText.getText().toString();
            try { //³×Æ®¿öÅ·Àº ¿¹¿Ü°¡ ¹ß»ýÇÒ ¼ö À־ Excption ¿¡·¯°¡ ÀÚÁֹ߻ýÇÔ.
                //http ¿äûÀ¸·Î ¾ÆÁÖ °£´ÜÈ÷ URL °´Ã¼¸¦ ¸¸µé¼ö ÀÖÀ½.
                URL url = new URL(urlStr);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.setConnectTimeout(10000); //10ÃÊ µ¿¾È ÀÀ´ä ¾øÀ¸¸é ²÷À½.
                int resCode = connection.getResponseCode(); //http ÀÀ´ä Äڵ带 ¹Þ±â
                if(resCode == 200) { //¼­¹ö Á¢¼ÓÀÌ Á¤»óÀÎ °æ¿ì ¼­¹ö¿¡¼­ 200 Äڵ带 º¸³»ÁÜ.
                    //connection¿¡ inputStreamÀ¸·Î ¹Þ°Ô µÇ´Âµ¥ ÇÑ ÁÙ¾¿ ¹ÞÀ»·Á¸é BufferReader
                    //·Î ¹ÞÀ¸¸é ¹Ù·Î º¯È¯ÀÌ ¾ÈµÇ¹Ç·Î InputStreamReader·Î Çѹø´õ °¨½ÎÁà¾ßÇÔ.
                    BufferedReader bufferedReader = new BufferedReader(
                            new InputStreamReader(connection.getInputStream(), "UTF-8"));
                    //°á°ú¹°À» ´ãÀ»¼ö ÀÖ´Â StringBuilder
                    StringBuilder stringBuilder = new StringBuilder();
                    String line = null;
                    while(true) {
                        //readLine() ÇÑÁÙ¾¿ ÀÐÀ» ¼ö ÀÖÀ½.
                        line = bufferedReader.readLine();
                        if(line == null) break;
                        stringBuilder.append(line + "\n");
                    }
                    bufferedReader.close();
                    connection.disconnect();
                    String result = stringBuilder.toString();
                    println(result); //È­¸éÀÇ TextView¿¡ °á°ú Ãâ·Â (Çڵ鷯ÀÌ¿ë)
                } else {
                    //resCode 200ÀÌ ¾Æ´Ñ °æ¿ì -> ¼­¹ö ¿¡·¯
                    Toast.makeText(getApplicationContext(), "Á¢¼Ó¿À·ù : " + resCode, Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    //¾²·¹µå¿¡¼­ UI¿¡ Á¢±Ù ÇÒ ¼ö ¾øÀ¸´Ï Çڵ鷯¸¦ ¸¸µé¾î ÁØ´Ù.
    private void println(final String data) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                textView.setText("");
                textView.append(data + "\n");
            }
        });
    }
}



[ÀÌ °Ô½Ã¹°Àº ÀÌ°æ¿ë´Ô¿¡ ÀÇÇØ 2016-12-22 20:52:32 ºÎ»ê20±â¿¡¼­ º¹»ç µÊ]

   

°Ô½Ã¹° 10°Ç
¹øÈ£ Á¦¸ñ ±Û¾´ÀÌ ³¯Â¥ Á¶È¸
10 [ÀÚ·á]  JSONÅë½Å - json.php ÀÌ°æ¿ë 02-18 1733
9 [ÀÚ·á]  JSONÅë½Å - manifests ÀÌ°æ¿ë 02-18 1595
8 [ÀÚ·á]  JSONÅë½Å - GetImage.java ÀÌ°æ¿ë 02-18 1601
7 [ÀÚ·á]  JSONÅë½Å - HttpParser.java ÀÌ°æ¿ë 02-18 1608
6 [ÀÚ·á]  JSONÅë½Å - RowData.java ÀÌ°æ¿ë 02-18 1716
5 [ÀÚ·á]  JSONÅë½Å - MainActivity.java ÀÌ°æ¿ë 02-18 1726
4 [ÀÚ·á]  JSONÅë½Å - listview_item.xml ÀÌ°æ¿ë 02-18 1663
3 [ÀÚ·á]  JSONÅë½Å - activity_main.xml ÀÌ°æ¿ë 02-18 1722
2 [ÀÚ·á]  À¥¼Ò½º °¡Á®¿À±â ÀÌ°æ¿ë 08-11 1744
1 [°øÁö]  ¼ö¾÷ÀÚ·á ÀÌ°æ¿ë 07-16 1977
 
 
 
Copyright ¨Ï wwwold.androidstudy.co.kr. All rights reserved.