如何从Android上的ASP.NET网站下载文件?

时间:2019-02-27 15:47:18

标签: java android

我正在将应用程序构建到基于ASP.NET的网站上,此下载管理器不起作用:

            @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.endsWith(".xlsx") || url.endsWith(".xls") || url.endsWith(".pdf") || url.endsWith(".doc")) {
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(
                        DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                String fileName = "Документ" + url.startsWith(".");
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
                DownloadManager dManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                dManager.enqueue(request);
                return true;
            }
            return true;
        }

    });

下载按钮代码:

<a href="JavaScript:openAttachment('/doc/28-02-2019.xlsx', 283662);">28-02-2019.xlsx</a>

1 个答案:

答案 0 :(得分:0)

如果您可以从网络浏览器下载文件,请遵循以下答案: Android: How to create a direct download link in android