웹뷰 사용시 한글 깨짐 및 파일 깨짐
웹뷰에서 파일을 받는대 파일용량이 이상하게 다운받아지고 한글도 깨져서 다운받아집니다
서버에 아파치랑 php쪽 utf8 설정은 다되어있고 저렇게 uf8 인코딩도 준거 같은대 뭘 잘못 한걸까요?
mWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
try {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file");
String filename = contentDisposition.replace("inline; filename=", "");
filename = URLEncoder.encode(filename,"UTF-8").replaceAll("\\+", "%20");
request.setTitle(URLUtil.guessFileName(url,contentDisposition,mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "파일을 다운로드중 입니다.", Toast.LENGTH_LONG).show();
} catch (Exception e) {
if (ContextCompat.checkSelfPermission(MainActivity.this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(getBaseContext(), "첨부파일 다운로드를 위해\n동의가 필요합니다.", Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
110);
} else {
Toast.makeText(getBaseContext(), "첨부파일 다운로드를 위해\n동의가 필요합니다.", Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
110);
}
}
}
}
});