Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android facebook like using webview

I use the following code to load a facebook like button inside a webview.

            likeWebView = (WebView)findViewById(R.id.webview);
            likeWebView.getSettings().setJavaScriptEnabled(true);

            url ="http://www.facebook.com/plugins/like.php?" +
            "href=" + URLEncoder.encode( "http://developers.facebook.com/docs/opengraph/" )
            + "&" +
            "layout=button_count&" +
            "show_faces=0&" +
            "width=90&" +
            "height=24&" +
            "locale=en_IN" +
            "colorscheme=light" ;

            likeWebView.loadUrl( url );

the problem is when the user is signing in the process redirects him to a blank page, how do i intercept this webview request and cancel this action/close webview ?

like image 560
ir2pid Avatar asked Jul 11 '11 07:07

ir2pid


1 Answers

public class WebViewPreLoad extends WebView{
public WebViewPreLoad(Context context) {
       super(context);
}
    public void loadUrl(String str){
    if(str.contains("something"))
            super.loadUrl(str);
        else 
                     hide this
    }
}

of course you will have to find the correct "if" for ur case

also, do the same thing with

 public void loadUrl(String url, Map<String,String> extraHeaders)

change the super statement to:

super.loadUrl(url, extraHeaders);
like image 161
Sherif elKhatib Avatar answered Sep 23 '22 13:09

Sherif elKhatib