2

After reading this post, I thought it would be plain sailing adding a WebView of one of my web pages. But how wrong i was, I can only assume the problem is due to scripting, but here is my code

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout);

    WebView mv = (WebView)findViewById(R.id.webView);
    mv.getSettings().setJavaScriptEnabled(true);

    final Activity activity = this;

    mv.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, description + " (" + errorCode + ") " + failingUrl, Toast.LENGTH_SHORT).show();
        }
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Toast.makeText(activity, url, Toast.LENGTH_SHORT).show();
            view.loadUrl(url);
            return true;
        }
    });
    mv.loadUrl("http://www.google.co.uk");

}

The code builds and runs, but the web page does not load i get an error code of -1 back and see the below line the logcat.

 01-11 14:46:55.362: D/chromium(22438): Unknown chromium error: -400

I have internet permission as another part of my application uses adverts and they are fine.

Community
  • 1
  • 1
Ne0
  • 2,566
  • 3
  • 31
  • 48

2 Answers2

0

Your implementation of shouldOverrideUrlLoading is confuses me. Why do you call loadUrl? Try to change to this:

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
   Toast.makeText(activity, url, Toast.LENGTH_SHORT).show();
   return super.shouldOverrideUrlLoading(view, url);
}
yoah
  • 7,030
  • 2
  • 25
  • 30
-3

Please check if you didn't forget to add :

<uses-permission android:name="android.permission.INTERNET" />

in you AndroidManifest.xml

EvZ
  • 10,710
  • 4
  • 35
  • 69