눈누난나

android webview download 본문

android

android webview download

히식 2017. 3. 2. 16:38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
webview.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                request.setMimeType(mimetype);
                request.addRequestHeader("User-Agent", userAgent);
                request.setDescription("Downloading file");
                String[] fileArray = url.split("/");
                String fileName = fileArray[fileArray.length - 1];
                request.setTitle(fileName);
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
                DownloadManager dm = (DownloadManager) getActivity().getSystemService(DOWNLOAD_SERVICE);
                dm.enqueue(request);
                Toast.makeText(getActivity().getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
            }
        });
주의점 Android 6.0(M)이상 버전부터 File에 권한 Permission 처리가 되어야함

'android' 카테고리의 다른 글

ViewPager 내부에 있는 Fragment Data갱신하기  (1) 2017.03.30
android soft keyboard setting  (0) 2017.03.08
RecyclerView 기초  (0) 2017.02.10
android sdk version  (0) 2017.02.09
Java source Hash key 얻기  (0) 2017.02.09
Comments