BrowserComponent "onDownloadStart" 事件

BrowserComponent "onDownloadStart" event

我正在尝试使用 BrowserComponent 构建一个简单的 Web 浏览器。是否有任何选项可以检查用户何时单击 "download" 按钮(如何检测下载)?直接用Android开发时,有一个事件"onDownloadStart"。有类似的吗?

谢谢

我们不支持这种行为,因为它不可移植。 Android 下载工具存储文件 "elsewhere" 并需要一些额外的权限。相反,您可以拦截 URL 导航逻辑并决定是否要执行下载,然后您可以使用类似 Util 下载方法的方法来执行实际的文件下载。

例如:

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;
});