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

<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将一个数字复制到剪贴板。但效果不太好。在浏览器中运行良好。但不在应用程序中

最佳答案

试试这个:

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;
            }
        }
    }

这通常会打开手机应用程序。如果你还有什么问题,尽管问。

10-02 05:12