Android Studio网络视图通话链接仅工作一次

时间:2017-09-25 08:42:34

标签: android html webview

我的活动java是这样的。问题是html Call链接

<a href="tel:555-555-5555">

只能使用一次。我尝试过很多东西,但是我无法让它发挥作用。我该如何解决这个问题?

public class Wall extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    String url = "http://##########.com/#############/";
    setContentView(R.layout.activity_wall);
    WebView webView = (WebView)findViewById(R.id.webView);
    webView.getSettings().setAppCacheMaxSize( 5 * 1024 * 1024 ); // 5MB
    webView.getSettings().setAppCachePath( getApplicationContext().getCacheDir().getAbsolutePath() );
    webView.getSettings().setAllowFileAccess( true );
    webView.getSettings().setAppCacheEnabled( true );
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setCacheMode( WebSettings.LOAD_DEFAULT ); // load online by default
    if ( !isNetworkAvailable() ) { // loading offline
        webView.getSettings().setCacheMode( WebSettings.LOAD_CACHE_ELSE_NETWORK );
    }
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String url) {
            if (url.startsWith("tel:")) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                startActivity(intent);
                webView.reload();
                return true;
            }
            if (url.startsWith("sms:")) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                startActivity(intent);
                webView.reload();
                return true;
            }
            webView.loadUrl(url);
            return true;
        }
    });
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadUrl("http://zacseed.com/parttime/");



    }



@Override
public void onBackPressed() {

    WebView webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new WebViewClient());
    if (webView.canGoBack()) {
        webView.goBack();
    } else {
        super.onBackPressed();
    }

}

private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( CONNECTIVITY_SERVICE );
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}}

我尝试设置一个按钮,用javascript将数字复制到剪贴板。但那并没有奏效。在浏览器中它工作正常。但不是在应用程序中

2 个答案:

答案 0 :(得分:0)

请检查此代码段

 @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
         if (url.indexOf("tel:") > -1) {
            startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
            return true;
        } 
    }

答案 1 :(得分:0)

试试这个:

private class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) { 
            if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url.startsWith("mailto:") || url.startsWith("mms:") || url.startsWith("mmsto:") || url.startsWith("market:")) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            } else {
                view.loadUrl(url);
                return true;
            }
        }
    }

通常应该打开手机应用程序。如果您还有其他问题,请询问。