我有简单的应用程序代码:
webView.getEngine().load("classpath:data/index.html");
自定义URLStreamHandler:
public class Handler extends URLStreamHandler { private final ClassLoader classLoader; public Handler() { this.classLoader = getClass().getClassLoader(); } public Handler(ClassLoader classLoader) { this.classLoader = classLoader; } @Override protected URLConnection openConnection(URL u) throws IOException { URL resourceUrl = classLoader.getResource(u.getPath()); if(resourceUrl == null) throw new IOException("Resource not found: " + u); return resourceUrl.openConnection(); } }
安装人:
URL.setURLStreamHandlerFactory(protocol -> { if(protocol.equals("classpath")) { return new Handler(); } else { return null; } });
它加载data/index.html:
Test Hello, World!!!![]()
但结果图像没有出现.
如何让WebView解析像"download.jpg"这样的相关链接?