안드로이드 개발 질문/답변
(글 수 45,052)
웹에서 이미지를 불러 오는걸 구현 하고 있습니다.
그런데 wifi에서는 이미지를 잘 불러 오다가도 3G에서는 아예 못 불러 오거나 230kb짜리 3장을 10분동안 불러 옵니다;;
혹시 이유를 아시는분 계신지요..
소스는 이렇습니다
void downloadFile(String fileUrl01, String fileUrl02, String fileUrl03) {
URL myFileUrl01 = null; // URL 타입의 myFileUrl을 NULL로 초기화 시켜줍니다.
URL myFileUrl02 = null; // URL 타입의 myFileUrl을 NULL로 초기화 시켜줍니다.
URL myFileUrl03 = null; // URL 타입의 myFileUrl을 NULL로 초기화 시켜줍니다.
showToast(fileUrl01);
showToast(fileUrl02);
showToast(fileUrl03);
try {
myFileUrl01 = new URL(fileUrl01); // 파라미터로 넘어온 Url을 myFileUrl에
// 대입합니다.
myFileUrl02 = new URL(fileUrl02); // 파라미터로 넘어온 Url을 myFileUrl에
// 대입합니다.
myFileUrl03 = new URL(fileUrl03); // 파라미터로 넘어온 Url을 myFileUrl에
// 대입합니다.
} catch (MalformedURLException e) // 예외처리를 해줍니다.
{
// Todo Auto-generated catch block
e.printStackTrace();
}
try {
// 실질적인 통신이 이루어지는 부분입니다.
// myFileUrl 로 접속을 시도합니다.
HttpURLConnection conn01 = (HttpURLConnection) myFileUrl01.openConnection();
HttpURLConnection conn02 = (HttpURLConnection) myFileUrl02.openConnection();
HttpURLConnection conn03 = (HttpURLConnection) myFileUrl03.openConnection();
conn01.setDoInput(true);
conn01.connect();
int length01 = conn01.getContentLength(); // 받아온 컨텐츠의 길이를 length 변수에
// 저장합니다.
InputStream is01 = conn01.getInputStream(); // InputStream is 변수에
// 받아온 InputStream을
// 저장합니다.
conn02.setDoInput(true);
conn02.connect();
int length02 = conn02.getContentLength(); // 받아온 컨텐츠의 길이를 length 변수에
// 저장합니다.
InputStream is02 = conn02.getInputStream(); // InputStream is 변수에
// 받아온 InputStream을
// 저장합니다.
conn03.setDoInput(true);
conn03.connect();
int length03 = conn03.getContentLength(); // 받아온 컨텐츠의 길이를 length 변수에
// 저장합니다.
InputStream is03 = conn03.getInputStream(); // InputStream is 변수에
// 받아온 InputStream을
// 저장합니다.
bitImg01 = BitmapFactory.decodeStream(is01); // 받아온 이미지를 bmImg에
// 넣어둡니다.
imgImg01.setImageBitmap(bitImg01);
bitImg02 = BitmapFactory.decodeStream(is02); // 받아온 이미지를 bmImg에
// 넣어둡니다.
imgImg02.setImageBitmap(bitImg02);
bitImg03 = BitmapFactory.decodeStream(is03); // 받아온 이미지를 bmImg에
// 넣어둡니다.
imgImg03.setImageBitmap(bitImg03);
} catch (IOException e) // 예외처리를 해줍니다.
{
e.printStackTrace();
}
}
소스가 돌다가 멈추는 부분은 conn01.connect(); 이부분 입니다