我的活動Java是這樣的。問題是HTML通話鏈接Android Studio的webview調用鏈接只能工作一次
<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。但那並沒有奏效。在瀏覽器中,它工作正常。但不是在應用
謝謝史蒂芬。我弄明白了。非常感謝 –
請接受然後作爲回答。所以它可以幫助其他人 – Steven