Android WebView“电话:"链接显示未找到网页 [英] Android WebView "tel:" links show web page not found
问题描述
我正在尝试让我的 android webview 应用程序打开电话:链接到手机.每次我打开电话链接时,它都运行良好并打开电话.但是,一旦我完成通话并返回应用程序,它就会出现一个页面,上面写着找不到网页电话:0000000000".然后我必须再次点击后退按钮才能进入我点击电话号码的页面.
I am trying to get my android webview app to open tel: links to the phone. Every time I open up a telephone link it works great and opens up the phone. However once I am done with my call and go back to the app it is at a page that says "Web Page Not Found tel:0000000000". Then I have to hit the back button once more to get to the page that I clicked the telephone number on.
有没有办法让它在不尝试在 webview 中找到页面以及在手机上打开它的情况下打开 TEL 链接?
Is there a way to get it to open the TEL link without trying to find the page in webview as well as opening it up on the phone?
这是我在 WebView 中使用的代码来覆盖它对 TEL 和 Mailto 链接的处理:
This is code I am using in WebView to override its handling of the TEL and Mailto links:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("mailto:") || url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);
}
view.loadUrl(url);
return true;
}
任何帮助将不胜感激.在过去的 2 个小时里,我一直在搜索 Goodle,但没有给出任何答案.
Any help would be appreciated. I have spent the last 2 hours scouring goodle and have failed to produce any answers.
推荐答案
好的所以我解决了我认为的问题.我只需要按如下方式分隔 URL 覆盖:
OK so I solved the issue I think. I just needed to separate the URL overrides as follows:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent);
view.reload();
return true;
}
view.loadUrl(url);
return true;
}
现在我的常规链接和电话链接一样有效.我还可以在那里添加 geo: 链接(如果需要),它不会给我带来之前在手机上打开地图时遇到的问题.
Now my regular links work as well as the tel links. I can also add in there for geo: links if I need to and it will not give me the issue that I was having before to open up maps on the phone.
这篇关于Android WebView“电话:"链接显示未找到网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!