336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.widget.TextView; public class MainActivity extends Activity { TextView result; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void mOnClick(View v) { Log.d("mOnClick", "mOnClick s1"); String html; downloadThread dt = new downloadThread("http://192.168.0.3:8182/books"); result = (TextView) findViewById(R.id.text); dt.start(); } class downloadThread extends Thread { public String addr; public downloadThread(String addr) { this.addr = addr; } public void run() { StringBuilder html = new StringBuilder(); try { URL url = new URL(addr); HttpURLConnection conn = (HttpURLConnection) url .openConnection(); if (conn != null) { conn.setConnectTimeout(10000); conn.setUseCaches(false); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader br = new BufferedReader( new InputStreamReader(conn.getInputStream())); while (true) { String line = br.readLine(); if (line == null) break; html.append(line + '\n'); } br.close(); } conn.disconnect(); } } catch (Exception ex) { } Message msg = new Message(); msg.obj = html.toString(); mHandler.sendMessage(msg); }; }; Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { result.setText((String) msg.obj); }; }; }
'Programming > JAVA,JSP' 카테고리의 다른 글
Eclipse Tips (0) | 2013.04.30 |
---|---|
JAVA MYSQL ANDROID REST 활용 (0) | 2013.04.28 |
JAVA MYSQL 활용 3 (0) | 2013.04.28 |
MYSQL REST 실습 코드 2 (0) | 2013.04.28 |
MYSQL & REST 실습 코드 (0) | 2013.04.28 |