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