2016-06-12 19 views
0

私はwebviewの下で私のウェブサイトのtel:リンクを使いたいですが、私がクリックするとこのエラーメッセージが出ます:ERR_UNKNOWN_URL_SCHEME。Android Webview tel:link ERR_UNKNOWN_URL_SCHEME

私はこの問題を知りませんが、この特別なリンクを除いてすべて正常に動作しています。

import android.content.Intent; 
import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.KeyEvent; 
import android.view.Window; 
import android.view.WindowManager; 
import android.webkit.URLUtil; 
import android.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class MainActivity extends AppCompatActivity { 

    private WebView webView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.activity_main); 

     webView = (WebView) findViewById(R.id.webView); 
     WebSettings webSettings = webView.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 
     webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); 
     webView.loadUrl("http://mywebsite.com"); 
     webView.setWebViewClient(new WebViewClient()); 
    } 

    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     if(URLUtil.isNetworkUrl(url)) { 
      return false; 
     } 

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(intent); 
     return true; 
    } 

    @Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) { 
     if (event.getAction() == KeyEvent.ACTION_DOWN) { 
      switch (keyCode) { 
       case KeyEvent.KEYCODE_BACK: 
        if (webView.canGoBack()) { 
         webView.goBack(); 
        } else { 
         finish(); 
        } 
       case KeyEvent.KEYCODE_MENU: 
        webView.loadUrl("javascript:open_menu()"); 
       return true; 
      } 

     } 
     return super.onKeyDown(keyCode, event); 
    } 


} 
+0

http://stackoverflow.com/questions/4338305/android-webview-tel-links-show-web-page-not-found –

+0

私は国民をコピーここからのboolen ...(http://stackoverflow.com/a/5545463/6442546) –

答えて

1

は最終的に私はこの問題を解決:

は、ここに私のMainActivity.javaです!ここで

は良いコードです:

import android.content.Intent; 
import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.KeyEvent; 
import android.view.Window; 
import android.view.WindowManager; 
import android.webkit.URLUtil; 
import android.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class MainActivity extends AppCompatActivity { 

private WebView webView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    setContentView(R.layout.activity_main); 

    webView = (WebView) findViewById(R.id.webView); 
    WebSettings webSettings = webView.getSettings(); 
    webSettings.setJavaScriptEnabled(true); 
    webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); 
    webView.loadUrl("http://www.mywebpage.com"); 
    webView.setWebViewClient(new WebViewClient() { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      if(URLUtil.isNetworkUrl(url)) { 
       return false; 
      } 

      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
      startActivity(intent); 
      return true; 
     } 

    }); 
} 

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { 
    if (event.getAction() == KeyEvent.ACTION_DOWN) { 
     switch (keyCode) { 
      case KeyEvent.KEYCODE_BACK: 
       if (webView.canGoBack()) { 
        webView.goBack(); 
       } else { 
        finish(); 
       } 
      case KeyEvent.KEYCODE_MENU: 
       webView.loadUrl("javascript:open_menu()"); 
      return true; 
     } 

    } 
    return super.onKeyDown(keyCode, event); 
} 


}