开发者

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 cance开发者_Python百科l this action/close webview ?


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);


I would actually use a WebViewClient's shouldOverrideUrlLoading method in this case.

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

likeWebView.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading (WebView view, String url) {
        if(url.contains("something")) return true;
        return false; //Default is to not override unless our condition is met.
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜