IT_Programming/Android_Java
[Android] Webview 에서 이미지 파일 다운로드 하기.
JJun ™
2015. 5. 7. 17:45
출처: http://soo84.tistory.com/entry/Androidwebview에서-파일-다운로드-처리하기
Webview에서 이미지 파일 다운로드 하기.
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 | class WebClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.e("url ", url); if(url.toLowerCase().endsWith(".jpg") || url.toLowerCase().endsWith(".png")) { Request request = new Request(Uri.parse(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //마지막 구분자를 파일명으로 지정. 확장자를 포함하여야 내 파일에서 열린다. String filename[] = url.split("/"); request.setDestinationInExternalPublicDir( Environment.DIRECTORY_DOWNLOADS, //Download folder filename[filename.length-1]); //Name of file DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); } else { view.loadUrl(url); } return true; } } | cs |
대소문자 체크를 한번에 하기 위해서는 다음과 같이 사용한다.
url.toLowerCase().endsWith(".jpg")); // 소문자 변환 함수
url.toUpperCase().endsWith(".JPG")); // 대문자 변환 함수