Page 724 - 3-2
P. 724
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Vector;
public class MyService extends Service implements Runnable {
static String num = null;
static String money = null;
int ja1;
public void onCreate() {
Log.d(this.getClass().getName(), " 온크리에이트");
super.onCreate();
Thread myThread = new Thread(this);
Log.d(this.getClass().getName(), " 쓰레드1");
myThread.start();
Log.d(this.getClass().getName(), " 쓰레드2");
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void run(){
while (true) {
StringBuilder jsonHtml = new StringBuilder();
Vector<ListItem> listItem = new Vector<ListItem>();
try {
URL url = new URL("http://192.168.0.76/num.php");
// 연결 url 설정
// 커넥션 객체 생성
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 연결되었으면.
Log.d(this.getClass().getName(), "url 접근");
if (conn != null) {
Log.d(this.getClass().getName(), "1 접근");
conn.setUseCaches(false);
// 연결되었음 코드가 리턴되면.
Log.d(this.getClass().getName(), "2 접근");
- 724 -