티스토리 뷰

android.os.NetworkOnMainThreadException 안드로이드 3.0 이후부터 발생되는 오류

android.os.NetworkOnMainThreadException 안드로이드 3.0 이후부터 발생되는 오류

private Bitmap GetImageFromURL(String strImageURL) ;

{

Bitmap imgBitmap = null;

;

try

{

URL url = new URL(strImageURL);

URLConnection conn = url.openConnection();

conn.connect();

;

int nSize = conn.getContentLength();

BufferedInputStream bis = new BufferedInputStream(conn.getInputStream(), nSize);

imgBitmap = BitmapFactory.decodeStream(bis);

;

bis.close();

}

catch (Exception e)

{

e.printStackTrace();

}

;

return imgBitmap;

}

사용하려면

3.0이후부터 에러발생

온크리에이트나 겓뷰 밑에 아래내용 추가해주면 잘불러옴(임시방편)

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectNetwork().penaltyLog().build());

Drawable dr ; //맨위에서 선언해줌

dr에 rul이미지 저장

dr = new BitmapDrawable(GetImageFromURL("http://icon.daumcdn.net/w/icon/1312/19/152729032.png"));

"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함