通过点击android资产文件夹中存在的HTML页面下载文件?

时间:2018-07-07 09:25:41

标签: android android-download-manager android-assets

我有一个HTML页面,该页面在加载时下载了PDF文件。从PC上运行时效果很好。我已经将相同的HTML文件以及J-Query库放在android的资产文件夹中。现在,我想通过单击活动中的任何按钮来在资产文件夹中加载相同的HTML以下载文件。 我为此使用以下代码:

String url = "http:file:///android_asset/getMyDynamicPdf.html?id=1&name=NAME&address=Delhi";
                Uri u = Uri.parse(url.replaceAll(" ", "%20"));
                String fileName = "FILENAME"+itemVO.get(getLayoutPosition()).getId()+".pdf";

                downloadFile(u, fileName); //Calling Download Function

以下是我使用的下载功能:

Utils.showToast(context, "Downloading File ....");
    DownloadManager.Request r = new DownloadManager.Request(uri);
    r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + File.separator + AppConstants.PDF_FILES, fileName);
    r.allowScanningByMediaScanner();
    r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    DownloadManager dm = (DownloadManager)context.getSystemService(DOWNLOAD_SERVICE);
    dm.enqueue(r);

我的查询是要传递URL的内容,以便它将文件下载到相应的文件夹中。

0 个答案:

没有答案