1

I am using a webview of height 60dp and i am passing a local html file to it, by default when i click a link in the webview it has to open the browser . But strangely its opens the links with in the webview, i also tried the webview client and trying to pass the response url to default browser through intent, but in vain..

my code snippet:

    WebViewClient yourWebClient = new WebViewClient()
       {

           @Override
           public boolean shouldOverrideUrlLoading(WebView  view, String  url)
           {
               System.out.println("Inside WebViewClient the URL is....."+url);

               Intent i = new Intent(Intent.ACTION_VIEW);
               i.setData(Uri.parse(url));
               startActivity(i);

            return true;
           }
       };

    WebView ad = (WebView) findViewById(R.id.webview1);
    ad.getSettings().setJavaScriptEnabled(true);
    ad.loadUrl(feed.getItem(position).getLink());
    ad.getSettings().setLoadWithOverviewMode(true);
    ad.getSettings().setUseWideViewPort(true);
    ad.setInitialScale(100);
        ad.setWebViewClient(yourWebClient);
    ad.loadUrl("file:///android_asset/advertisement.htm");
skaffman
  • 398,947
  • 96
  • 818
  • 769
Chanakya Vadla
  • 3,019
  • 2
  • 22
  • 24

1 Answers1

1

Stop the current webview loading. As ad is the object of WebView, Try doing it this way:

  @Override
       public boolean shouldOverrideUrlLoading(WebView  view, String  url)
       {
           System.out.println("Inside WebViewClient the URL is....."+url);

            ad.stopLoading();
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);

        return true;
       }

Also add this while adding settings for your WebView:

 ad.getSettings().setSupportMultipleWindows(false);

Edit:

Try associating a chrome client with your webview and then check:

 ad.setWebChromeClient(new MyWebChromeClient());

Hope this works for you.

Usama Sarwar
  • 8,922
  • 7
  • 54
  • 80
  • Thanks For the answer Usama Sarwar, But unfortunately it doesn't solve my problem. If you see the advertisement.html file i am loading has a java script code from google which generates ads with corresponding links to the ad. your code and my code will work when it tries to open a hyperlink from the webview, but the sysout in the "WebViewClient" is not printing in either cases. – Chanakya Vadla Dec 29 '11 at 08:22
  • Thanks for your reply, now am using a different html file and my problem solved. – Chanakya Vadla Jan 03 '12 at 07:05