download - BrowserComponent "onDownloadStart" event
问题描述
I'm trying to build a simple web browser using BrowserComponent. Are there any options to check when a user clicks on a "download" button (how to detect download)? When developing directly with Android, there is an event "onDownloadStart". Is there something similar?
Thanks
解决方案
We don't support that behavior as it isn't portable. Androids download facility stores files "elsewhere" and requires some additional permissions. Instead you can intercept the URL navigation logic and decide whether you want to perform a download or not, you can then use something like the Util
download methods to perform the actual file download.
e.g.:
bc.addBrowserNavigationCallback(url -> {
// *** WARNING: this code runs off the EDT and must not block!!!! ***
if(shouldIDownloadThisURL(url) {
String file = getStorageFileNameForUrl(url);
Util.downloadUrlToStorageInBackground(url, file,
ev -> fileDownloadCompleted(file));
return false;
}
return true;
});
推荐阅读
- javascript - 为什么带有 <=, >= 的公式可以工作,而简单的 == 却不行
- python - 无法使用 PIL 打开照片
- jquery - 执行顺序执行异步 ajax 调用的方法
- android - 具有不同工具栏和菜单的导航组件
- java - 在使用自签名证书签名的服务器上调用 API
- python - 我应该如何在 dask 分布式中为每个工作人员加载一个内存密集型辅助对象?
- .net - 如何将库项目中的 ASP.NET Core 3.0 类型用于共享控制器、中间件等?
- asp.net-mvc - 如何以编程方式解析 Outlook 服务器上的电子邮件并执行脚本/任务
- elasticsearch - Elasticsearch Java API:等到在搜索结果中找到文档?
- c - 有没有办法使用指针+变量来遍历数组?