[英]Open telephone number link
我想打开 MS Teams 以拨打 HTML 网页上带有<a href="tel:.....
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
有任何想法吗?
好的,我找到了一种使用电话的方法:链接。 我的代码仅适用于 windows 所以如果你想使用跨平台,你必须先做一个检查,比如这里
String st = "<html>\r\n<a href=\"tel:+4917312345678\">+4917312345678</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 {
Runtime rt = Runtime.getRuntime();
String url = e.getDescription();
System.out.println(url);
rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
editorPane.setEditable(false);
editorPane.setBounds(72, 244, 423, 137);
panel_3.add(editorPane);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.