Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook like button opens blank page in android

I am trying to like a url on facebook through my android app. I am using android webview to show the like button but when i click it, nothing happens and it shows a blank page.But when i use the same url in the android web browser in proceeds as expected and likes the link.

I am using the following code

 WebView like_btn = (WebView) findViewById(R.id.WEBView);
 String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://google.com";
    like_btn.loadUrl(url);
    like_btn.getSettings().setJavaScriptEnabled(true);
    like_btn.getSettings().setAppCacheEnabled(true);
    like_btn.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

Am i doing it right or is there any other way to achieve this functionality? There are other questions related to this issue on SO but they only say how to close the blank page. The real issue is that it doesn't even 'like' the url.

like image 221
Talha Mir Avatar asked Nov 13 '22 13:11

Talha Mir


1 Answers

The problem is that in Android, the webview and the browser does not share cookies, so the webview does not know the Facebook identity of the user. See this answer here Android WebView for Facebook Like Button

like image 119
Ming Li Avatar answered Nov 15 '22 04:11

Ming Li