0

我在我的 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;
    }
}
}
4

2 回答 2

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 中禁用它们,它将无法正常工作!

于 2012-10-04T21:37:58.277 回答
0

尝试覆盖WebViewClient类的 shouldOverrideUrlLoading 方法。调用 webview.setWebViewClient(customWebViewClient) 或 webview.setWebViewClient(new WebViewClient{...})。在 shouldOverrideUrlLoading 方法中,检查不同类型的链接(tel:、mailto:、geo: 等)并手动创建意图并触发它们。

于 2012-10-04T20:29:48.847 回答