【发布时间】:2021-05-29 17:43:01
【问题描述】:
我想打开 MS Teams 以拨打带有 <a href="tel:..... 标签的 HTML 网页上的号码。
据我所知,Java 中的 HTML 版本非常旧,可能包含的版本不支持 tel:。但是,我尝试了这段代码,它适用于普通 HMTL 链接。
String st = "<html>\r\n<a href=\"tel:+4917312345678\">0173 12345678</a>\r\n</html>";
editorPane = new JEditorPane("text/html", st);
// handle link events
editorPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // roll your own link launcher or use Desktop if J6+
}
});
editorPane.setEditable(false);
editorPane.setBounds(72, 244, 423, 137);
panel_3.add(editorPane);
但这不适用于tel: 链接
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "java.net.URL.toURI()" because the return value of "javax.swing.event.HyperlinkEvent.getURL()" is null
有什么想法吗?
【问题讨论】:
标签: java swing jeditorpane tel