错误 net::err_unknown_url_scheme 电话:
Posted
技术标签:
【中文标题】错误 net::err_unknown_url_scheme 电话:【英文标题】:Error net::err_unknown_url_scheme tel: 【发布时间】:2017-05-05 10:03:26 【问题描述】:我用 android Studio 构建了一个 webview 应用程序,当我从应用程序返回错误 net::err_unknown_url_scheme 按此链接时,在我的网站上我有一个类似 tel:0752118 的链接
这是我的 MainActivity.java
package totalonlinesrl.totalonline;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.net.Uri;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
private WebView webView;
private ProgressBar progressBar;
private LinearLayout layoutProgress;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
layoutProgress = (LinearLayout) findViewById(R.id.layoutProgress);
webView.setVisibility(View.GONE);
WebSettings settings = webView.getSettings();
settings.setjavascriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setDisplayZoomControls(false);
webView.setWebViewClient(new WebViewClient()
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
view.loadUrl(url);
return true;
@Override
public void onPageFinished(WebView view, String url)
webView.setVisibility(View.VISIBLE);
layoutProgress.setVisibility(View.GONE);
progressBar.setIndeterminate(false);
super.onPageFinished(view, url);
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
layoutProgress.setVisibility(View.VISIBLE);
progressBar.setIndeterminate(true);
super.onPageStarted(view, url, favicon);
);
if(isOnline())
webView.loadUrl("https://total-online.eu/");
else
String summary = "<html><body><font color='red'>No Internet Connection</font></body></html>";
webView.loadData(summary, "text/html", null);
toast("No Internet Connection.");
private void toast(String message)
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
private boolean isOnline()
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return (netInfo != null && netInfo.isConnected());
有什么办法吗?
【问题讨论】:
关注此链接mariusbancila.ro/blog/2015/09/17/… 【参考方案1】:如果链接包含地理位置、电话号码和电子邮件地址,您可以使用下面的代码切换到搜索屏幕和邮件客户端。
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;
else if (url.contains("mailto:"))
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
else if(url.contains("geo:"))
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(url)));
return true;
else
view.loadUrl(url);
return true;
【讨论】:
以上是关于错误 net::err_unknown_url_scheme 电话:的主要内容,如果未能解决你的问题,请参考以下文章