我正在尝试使用WebView和DoanloadManager下载字体。我使用Environment.getExternalStorageDirectory() + "/Fonts/"
将下载文件夹目录设置为“Fonts”文件夹,但我创建的是另一个不需要的目录,sdcard/storage/emulated/0/Fonts/
。我的代码出了什么问题?以下是完整的代码段:
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
String filename = URLUtil.guessFileName(url, contentDisposition, mimeType);
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.setMimeType(mimeType);
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(filename);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory() + "/Fonts/", filename);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
答案 0 :(得分:0)
sdcard/storage/emulated/0/
是您在使用模拟器时通常由Environment.getExternalStorageDirectory()
返回的路径。
Environment.getExternalStorageDirectory()
可以返回任何文件夹,但您无法真正预料到该路径。今天我们在同一设备上有多个配置文件。此外,这可以根据Android API版本进行更改。