0
아래 코드는 Android 에뮬레이터에서는 작동하지만 실제 장치에서는 작동하지 않습니다. inputstream.available()
은 에뮬레이터에서 장치에 -1을 반환하면 int
값을 수천 단위로 반환합니다. 어떤 도움이 필요합니까?android의 데이터 연결성 : InputStream의`available`이 다른 값을 반환합니다.
코드 :
try {
URL url = new URL("http://www.google.com");
Log.d(TAG,"Set URL");
urlConnection = (HttpURLConnection) url.openConnection();
//urlConnection.connect();
Log.d(TAG,"Open connection");
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
Log.d(TAG,"get input");
str="Connect time out::"+urlConnection.getConnectTimeout()+
"\nContent length:"+urlConnection.getContentLength()+
"\nRead time out::"+ urlConnection.getReadTimeout()+
"\nResponse messgae::"+urlConnection.getResponseMessage()+
"\nAvailable bytes::::"+in.available();
Log.d(TAG,""+str);
read(in);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
urlConnection.disconnect();
}