Problems downloading PopUp window file in Android Studio

0

I have an application for android, where I am using WebView to show a web page, from which to download files it shows a popup window (see image) where there are DOWNLOAD buttons to download files, but when pressing DOWNLOAD DO NOT download.

I'm using this code:

public class enotificaciones extends AppCompatActivity {
WebView notificacion;
String urlWeb="https://www.miwesite.pe";

@Override
public void onBackPressed() {
    if (notificacion.canGoBack()) {
        notificacion.goBack();
    } else {
        super.onBackPressed();
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_enotificaciones);
    notificacion = (WebView) findViewById(R.id.notificacion);
    notificacion.getSettings().setJavaScriptEnabled(true);
    notificacion.setFocusable(true);
    notificacion.setFocusableInTouchMode(true);
    notificacion.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    notificacion.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    notificacion.getSettings().setDomStorageEnabled(true);
    notificacion.getSettings().setDatabaseEnabled(true);
    notificacion.getSettings().setAppCacheEnabled(true);
    notificacion.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    notificacion.loadUrl("https://www.miwesite.pe");
    notificacion.setWebViewClient(new WebViewClient());

    notificacion.getSettings().setSupportMultipleWindows(true);
    notificacion.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    notificacion.getSettings().setAllowFileAccess(true);
    notificacion.getSettings().setJavaScriptEnabled(true);
    notificacion.getSettings().setBuiltInZoomControls(true);
    notificacion.getSettings().setDisplayZoomControls(false);
    notificacion.getSettings().setLoadWithOverviewMode(true);
    notificacion.getSettings().setUseWideViewPort(true);


    final enotificaciones activity = this;
    notificacion.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            activity.setProgress(progress * 1000);
        }
    });
    notificacion.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, "Problems with server " + description, Toast.LENGTH_SHORT).show();
        }
    });

    notificacion.loadUrl(urlWeb);

    //descargar archivo
    notificacion.setDownloadListener(new DownloadListener()
    {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
            request.allowScanningByMediaScanner();

            request.setMimeType(mimetype);
            //------------------------COOKIE------------------------
            String cookies = CookieManager.getInstance().getCookie(url);
            request.addRequestHeader("cookie", cookies);
            //------------------------COOKIE------------------------
            request.addRequestHeader("User-Agent", userAgent);
            request.setDescription("Descargando Archivo...");
            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));
            final DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);

            new Thread("Browser download") {
                public void run() {
                    dm.enqueue(request);
                }
            }.start();
        }
    });
}
}
    
asked by Alancito 10.12.2018 в 21:50
source

0 answers