0

I am trying to override the web client but I get "HellowWebViewClient cannot be resolved to a type" error.. What am I doing wrong?

package com.example.name;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

public class MainActivity extends Activity {
WebView browser;

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

        // find the WebView by name in the main.xml of step 2
        browser=(WebView)findViewById(R.id.wvwMain);

        // Enable javascript
        browser.getSettings().setJavaScriptEnabled(true);  

        // Set WebView client
        browser.setWebChromeClient(new HellowWebViewClient());

        // Load the webpage
        browser.loadUrl("http://www.website.com/");


    }
}
Adrian M.
  • 7,183
  • 15
  • 46
  • 54

2 Answers2

2

I think you mean "HelloWebViewClient" but wrote "Hello w WebViewClient".

Björn
  • 608
  • 2
  • 7
  • 19
1

Here's a tutorial with example code for the WebChromeClient (what your HwllowWebViewClient should be): http://ganeshtiwaridotcomdotnp.blogspot.com/2011/09/android-webview-webchromeclient-example.html

If you want to set a WebViewClient, you should check this out from the developer site: http://developer.android.com/guide/webapps/webview.html#HandlingNavigation

And here's a stackoverflow question about the differences between the two: What's the difference between setWebViewClient vs. setWebChromeClient?

EDIT: taking the sample WebViewClient from the developer site and renaming it for your purposes (Notice that we are setting the web view client and not the chrome client):

package com.example.name;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

public class MainActivity extends Activity {
WebView browser;

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

        // find the WebView by name in the main.xml of step 2
        browser=(WebView)findViewById(R.id.wvwMain);

        // Enable javascript
        browser.getSettings().setJavaScriptEnabled(true);  

        // Set WebView client
        // Notice that we are setting the web view client and not the chrome client.
        browser.setWebViewClient(new HellowWebViewClient());

        // Load the webpage
        browser.loadUrl("http://www.website.com/");


    }

    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().equals("www.example.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));
            startActivity(intent);
            return true;
        }
    }
}
Community
  • 1
  • 1
Flynn81
  • 4,108
  • 29
  • 28