2014-08-28 100 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

相关问题