【发布时间】:2019-02-14 06:44:43
【问题描述】:
我有 javascript 代码,我使用锚标记的下载属性来设置文件名。 以下是我的代码 sn-p:
const fileReader = new FileReader();
fileReader.onload = () => {
const link = <HTMLAnchorElement>windowService.document.createElement("a");
link.href = fileReader.result;
link.setAttribute("download", fileName);
link.target = "_blank";
windowService.document.body.appendChild(link);
link.click();
};
fileReader.readAsDataURL(testFile);
}
其中 testFile 是数据块。此代码适用于所有浏览器、iOS 应用程序,但不适用于 android 应用程序。 在 Android webView 上,调用了 onDownloadListener 函数,只设置了 url 参数,没有设置其他参数。
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
// url: set as base64 encoded content
// no other attribute is set. I understand content disposition can be used to get file name but that is not set either
}
}
我想在锚点的下载属性中获取分配给文件的文件名。如何检索相同的文件名?我正在使用 Android API 28 进行测试。
【问题讨论】:
标签: javascript java android android-webview