Производит ли Android-WebViewClient вызов сервера перед вызовом onDownloadRequested ()? - PullRequest
0 голосов
/ 04 ноября 2019

Сервер получает вызов на загрузку до того, как управление приходит onDownloadRequested(String url, String userAgent, String contentDisposition,String mimetype, long contentLength), Мой вопрос заключается в том, что если существует возможность просмотра веб-страницы для вызова сервера, чтобы получить подробную информацию о url + contentdisposition + mimeType и т.д.?

@Override
    public void onDownloadRequested(String url, String userAgent, String contentDisposition,
                                    String mimetype, long contentLength) {
        /*Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(s));
        startActivity(i);*/
        downloadViaDownloadManager(url,userAgent,contentDisposition,mimetype);
    }

и downloadViaDownloadManager () имеет реализацию диспетчера загрузки.

Я проверил эту проблему в отношении вызова к серверу.

Вот метод dowloadViaDownloadManager ().


    private void downloadViaDownloadManager(String url, String userAgent, String contentDisposition, String mimetype) {
        Uri uri;
        try {
            uri = Uri.parse(url);
            DownloadManager.Request request = new DownloadManager.Request(uri);

            request.setMimeType(mimetype);

            String cookies = CookieManager.getInstance().getCookie(url);
            request.addRequestHeader("cookie", cookies);

            request.addRequestHeader("User-Agent", userAgent);
            request.setDescription("Downloading file...");
            request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimetype));

            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            dm.enqueue(request);

            Toast.makeText(getApplicationContext(), R.string.download_in_progress, Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(mActivity, R.string.url_not_supported , Toast.LENGTH_SHORT).show();
        }
    }

...