2014-08-28 45 views
1

我的android應用程序中有一個webview,並且在服務器上有一個.xls文件我想將該文件下載到我的設備中,這將在我點擊按鈕時執行在webview中。XLS文件從webview下載到本地Android設備上


總之,我想通過的WebView按鈕從服務器上下載.xls文件到Android設備上點擊


回答

0

DownloadListener到您的WebView。

例子:

webview.setDownloadListener(new DownloadListener() { 
     @Override 
     public void onDownloadStart(String url, String userAgent, 
       String contentDisposition, String mimetype, 
       long contentLength) { 
      // handle download, here we use brower to download, also you can try other approach. 
      Uri uri = Uri.parse(url); 
      Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
      startActivity(intent); 
     } 
    }); 

或者

webview.setDownloadListener(new DownloadListener() { 
     public void onDownloadStart(String url, String userAgent, 
       String contentDisposition, String mimetype, 
       long contentLength) { 
        Request request = new Request(
          Uri.parse(url)); 
        request.allowScanningByMediaScanner(); 
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download"); 
        DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
        dm.enqueue(request);   

     } 
    }); 
+0

維傑先生,它不工作我嘗試了這就是爲什麼我在計算器上 – 2014-08-30 04:46:00

+0

張貼您沒有提到你已經嘗試過什麼樣的代碼,這就是爲什麼我已發佈答案。 – 2014-08-30 06:54:04

相關問題