我在一个适用于所有网址的活动中使用了android.webview,但是如果有任何跟踪网址,它会在我的屏幕中显示市场详细信息错误。应该在网络视图中打开浏览器后打开此网址。它只能在我的活动中使用。
public class WebViewActivity extends Activity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webview1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://trax.claym.in/click.php?c=209&key=c73n783g2tm2377yd73d6n5m");
// webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
if (errorCode==-10) {
String errormsg=description;
String url=failingUrl;
webView.setWebChromeClient(new WebChromeClient(){
});
/* Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
WebViewActivity.this.finish();*/
}
// TODO Auto-generated method stub
Log.e("error code:" ,""+errorCode);
super.onReceivedError(view, errorCode, description, failingUrl);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view,
String url) {
// TODO Auto-generated method stub
Log.e("WebResourceResponse" ,""+url);
return super.shouldInterceptRequest(view, url);
}
@Override
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
// TODO Auto-generated method stub
return super.shouldOverrideKeyEvent(view, event);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
String myurl=url;
Log.e("url", ""+myurl);
return super.shouldOverrideUrlLoading(view, url);
}
});
//webView.loadUrl("http://trax.claym.in/click.php?c=209&key=c73n783g2tm2377yd73d6n5m");
//webView.loadUrl("https://www.google.co.in/");
//animation url
// webView.loadUrl("http://www.dogwonder.co.uk/wp-content/uploads/2009/12/tumblr_ku2pvuJkJG1qz9qooo1_r1_400.gif");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// TODO Auto-generated method stub
return super.onKeyDown(keyCode, event);
}
}