当用户选择我的应用溢出操作栏中提供的“生成excel”选项时,我正在应用中的搜索结果中生成Excel工作表。我可以将该文件保存在“file:///storage/emulated/0/Download/tempfile.xls”的位置,没有任何问题,但我想通过DownloadManager在下载菜单中提供生成的Excel工作表 - / p>
String filepath = "file://" + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/tempfile.xls";
Uri uriDownloadFile = Uri.parse(filepath );
DownloadManager.Request request = new DownloadManager.Request(uriDownloadFile);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "tempfile.xls");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); // to notify when download is complete
request.allowScanningByMediaScanner();// if you want to be available from media players
DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
manager.enqueue(request);
我尝试使用Uri.parse(上面的第二行代码)将本地文件路径更改为uri。但是,我以下面的错误结束了 -
java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: file:///storage/emulated/0/Download/tempfile.xls