안드로이드 개발 질문/답변
(글 수 45,052)
말그대로 html 을 스트링 값으로 저장할때 한글만 깨짐현상입니다.
html다운 소스
String DownloadHtml(String addr) {
HttpGet httpget = new HttpGet(addr);
DefaultHttpClient client = new DefaultHttpClient();
StringBuilder html = new StringBuilder();
try {
HttpResponse response = client.execute(httpget);
BufferedReader br = new BufferedReader(new
InputStreamReader(response.getEntity().getContent()));
for (;;) {
String line = br.readLine();
if (line == null) break;
html.append(line + '\n');
}
br.close();
}
catch (Exception e) {;}
return html.toString();
}
-----------------------------
메인 액티비티
art_html = DownloadHtml("해당 url");
WebView mWebView;
mWebView.loadData(art_html, "text/html", "euc-kr");
--------------------------------
했을때 한글깨짐현상이 나더라고요
태그와 이미지는 제대로 들어갑니다.
인코딩문제인것같은데 html 상에서도 헤더부분에
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr"> 정의 되어있습니다.
utf-8 로 해도 마찬가지구요
html 소스를 string 값으로 넣을때 깨져서 들어오는것같은데 어떻게 해결해야할까요
부탁드립니다 ㅠㅠ
html다운 소스
String DownloadHtml(String addr) {
HttpGet httpget = new HttpGet(addr);
DefaultHttpClient client = new DefaultHttpClient();
StringBuilder html = new StringBuilder();
try {
HttpResponse response = client.execute(httpget);
BufferedReader br = new BufferedReader(new
InputStreamReader(response.getEntity().getContent()));
for (;;) {
String line = br.readLine();
if (line == null) break;
html.append(line + '\n');
}
br.close();
}
catch (Exception e) {;}
return html.toString();
}
-----------------------------
메인 액티비티
art_html = DownloadHtml("해당 url");
WebView mWebView;
mWebView.loadData(art_html, "text/html", "euc-kr");
--------------------------------
했을때 한글깨짐현상이 나더라고요
태그와 이미지는 제대로 들어갑니다.
인코딩문제인것같은데 html 상에서도 헤더부분에
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr"> 정의 되어있습니다.
utf-8 로 해도 마찬가지구요
html 소스를 string 값으로 넣을때 깨져서 들어오는것같은데 어떻게 해결해야할까요
부탁드립니다 ㅠㅠ




자답입니다.
html 소스를 스트링으로 받을때 (url.openStream(),"EUC-KR")
한후에 스트링값에서 EUC-KR을 UTF-8 로 바꿔서 loadData(source, "text/html", "UTF-8"); 로 로드데이터 하니깐 잘나오네요