我已经在我的Android应用程序中添加了一个webbrowser(webview),但是当我去一个网站里面有一个电话或导航按钮,比如谷歌或电话簿页面时,它只是说无法打开电话:一些数字。如果它是导航按钮,应该打开拨号器或谷歌地图。我怎么处理这个?请帮忙
代码:
package com.mysoftware.mysoftwareos.launcher;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class PeopleSearchActivity extends Activity implements OnClickListener {
WebView peoplesearchWebView;
EditText peoplesearchEditText;
Button peopleSearchButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.peoplesearch);
//Import views
peoplesearchWebView = (WebView)findViewById(R.id.peoplesearchWebView);
peoplesearchEditText = (EditText)findViewById(R.id.peoplesearchEditText);
peopleSearchButton = (Button)findViewById(R.id.peopleSearchButton);
//Setup onClickListener for the buttons
peopleSearchButton.setOnClickListener(this);
//Setup WebView
peoplesearchWebView.getSettings().setJavaScriptEnabled(false);
peoplesearchWebView.getSettings().setBuiltInZoomControls(false);
peoplesearchWebView.setWebViewClient(new myWebViewClient());
}
public void onClick(View src) {
switch(src.getId()) {
case R.id.peopleSearchButton:
String searchUrl;
searchUrl = ("http://m.gulesider.no/query?search_word=" + peoplesearchEditText.getText().toString() + "&geo_area=&what=mobwp&hpp=10");
peoplesearchWebView.loadUrl(searchUrl);
}
}
public class myWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(String url, WebView view) {
view.loadUrl(url);
return true;
}
}
}
答案 0 :(得分:0)
尝试覆盖WebViewClient类的shouldOverrideUrlLoading方法。调用webview.setWebViewClient(customWebViewClient)或webview.setWebViewClient(new WebViewClient {...})。在shouldOverrideUrlLoading方法中,检查不同类型的链接(tel:,mailto:,geo:等)并手动创建意图并将其关闭。
答案 1 :(得分:0)
使您的webView设置包含所有这些
peoplesearchWebView.getSettings().setJavaScriptEnabled(true);
peoplesearchWebView.getSettings().setBuiltInZoomControls(true);
peoplesearchWebView.setWebViewClient(new myWebViewClient());
peoplesearchWebView.setInitialScale(1);
peoplesearchWebView.getSettings().setBuiltInZoomControls(true);
peoplesearchWebView.getSettings().setUseWideViewPort(true);
网站上的某些字段是java,所以如果你在cade中禁用它们就行不通!