Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XLS文件从webview下载到我的android设备上的本地_Android_Webview - Fatal编程技术网

XLS文件从webview下载到我的android设备上的本地

XLS文件从webview下载到我的android设备上的本地,android,webview,Android,Webview,我的android应用程序中有一个webview,服务器上有一个.xls文件。我想将该文件下载到我的设备中,这将在我单击webview中的按钮时执行 简而言之,我想通过webview的点击按钮将.xls文件从服务器下载到android设备 将DownloadListener设置为您的WebView 例如: webview.setDownloadListener(new DownloadListener() { @Override public void onDow

我的android应用程序中有一个webview,服务器上有一个.xls文件。我想将该文件下载到我的设备中,这将在我单击webview中的按钮时执行

简而言之,我想通过webview的点击按钮将.xls文件从服务器下载到android设备

将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);
        }
    });


Vijay先生,它不起作用,我试过了,这就是为什么我在StackOverflow上发布了你没有提到你尝试过的代码,这就是为什么我发布了答案。
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);        

        }
    });