package com.webview;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Webview_integrationActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView mywebview = (WebView) findViewById(R.id.webView1);
mywebview.setWebViewClient(new MyWebViewClient());
WebViewClient client = new MyWebViewClient()
{
@Override
public void launchExternalBrowser(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
};
}
}
***************************************************************************************
package com.webview;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public abstract class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.google.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
launchExternalBrowser(url);
return true;
}
public abstract void launchExternalBrowser(String url);
}
**当我运行此程序时,我收到错误消息“无法实例化 MyWebViewClient 类型”。我知道那是因为该类是抽象的。但是如何解决我的问题。我已经粘贴了两个类的代码使用。