Android WebView 标记 a 无法使用 tel Uri 启动意图
Android WebView tag a can not start a intent with tel Uri
点击 Common tag a contains 'tel:' Uri in HTML cannot start a intent in Android.
这是我的 Android 代码:
WebSettings webSettings = mWebView.getSettings();
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //no cache
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
//This method will only be invoked with GET request
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//Log.d("DEBUG-URL","url:"+url);
if(url.startsWith(WebView.SCHEME_TEL)){
Intent intent = new Intent(Intent.ACTION_DIAL,
Uri.parse(url));
startActivity(intent);
return true;
}
view.loadUrl(url);
return true;
}
});
当我在 WebView 中单击 url 时,net: ERR_UNKNOWN_URL_SCHEME throws.
我添加点击事件,调用event.preventDefault(),然后我使用Ajax GET 请求。此问题已解决。
$("#a_get").on("click",function(event){
event.preventDefault();//invalidate
$.ajax({
type: "GET",
url: a_href,
success: function(result){
},
error: function(result){
}
});
});
点击 Common tag a contains 'tel:' Uri in HTML cannot start a intent in Android.
这是我的 Android 代码:
WebSettings webSettings = mWebView.getSettings();
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //no cache
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
//This method will only be invoked with GET request
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//Log.d("DEBUG-URL","url:"+url);
if(url.startsWith(WebView.SCHEME_TEL)){
Intent intent = new Intent(Intent.ACTION_DIAL,
Uri.parse(url));
startActivity(intent);
return true;
}
view.loadUrl(url);
return true;
}
});
当我在 WebView 中单击 url 时,net: ERR_UNKNOWN_URL_SCHEME throws.
我添加点击事件,调用event.preventDefault(),然后我使用Ajax GET 请求。此问题已解决。
$("#a_get").on("click",function(event){
event.preventDefault();//invalidate
$.ajax({
type: "GET",
url: a_href,
success: function(result){
},
error: function(result){
}
});
});