2017-06-17 12 views
0

ダウンロードリスナーは決して呼び出さず、私も動的ダウンロードリンクを取得していません。Webviewダウンロードリスナーは決してコールしません。

ボタンをクリックしながら、私はダウンロードボタンをクリックしながら、それが正常に直接Chromeブラウザ経由でドキュメントをダウンロードします、ドキュメントのダウンロードリンクを生成しますが、Web表示を使用することはありませんが、ダウンロードボタンが含まれている1つのウェブサイトを持っています自動的にドキュメントをダウンロードし、リスナーの呼び出しも受け付けません。

webView.loadUrl(WEBSITELINK); 

webView.setWebViewClient(new WebViewClient() { 

     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { 
      Log.v("Url:","shouldOverrideUrlLoading"); 
      return true; 
     } 

     @Override 
     public void onPageFinished(WebView view, String url) { 

      // download link generates dynamically by clicking on button 

      webView.loadUrl("javascript:(function(){document.getElementById('download').click();})()"); 

     } 



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); 
      //------------------------COOKIE!!------------------------ 
      String cookies = CookieManager.getInstance().getCookie(url); 
      request.addRequestHeader("cookie", cookies); 
      //------------------------COOKIE!!------------------------ 
      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(), "Downloading File", Toast.LENGTH_LONG).show(); 
     } 
    }); 

答えて

0

setDownloadListenerは、コンテンツを考えていないのWebViewは、このリンクsetDownloadListener

またはこのlink

+0

完全にコールリスナーを強制する方法はありますか? – Nik

0

内部に従ってください詳細については、レンダリングエンジン

で扱うことができリスナーを設定しますoncreateメソッドこのコードを書く

webView = (WebView) findViewById(R.id.webView); 
    WebSettings webSettings = webView.getSettings(); 
    webSettings.setJavaScriptEnabled(true); 
    webView.loadUrl("place your link here"); 
    webView.setWebViewClient(new WebViewClient()); 

    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.allowScanningByMediaScanner(); 
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! 

      DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
      dm.enqueue(request); 
      Toast.makeText(getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded 
        Toast.LENGTH_LONG).show(); 

     } 
    }); 

} 
関連する問題