5

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.

Talha Mir
  • 1,228
  • 11
  • 19
  • I think part of 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 http://stackoverflow.com/questions/5108088/android-webview-for-facebook-like-button – Ming Li Jan 22 '13 at 18:53
  • this solved my issue, post this as answer i will accept – Talha Mir Jan 23 '13 at 06:10
  • check this post, there is well-formed library to solve this issue: http://stackoverflow.com/a/23853937/1891118 – Oleksii K. Jun 12 '14 at 14:12

1 Answers1

1

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

Community
  • 1
  • 1
Ming Li
  • 15,672
  • 3
  • 37
  • 35
  • You are right.Now i am opening the log in screen in the webview instead of separate window and it works great.i just have to bypass the blank screen which appears after log in which can be done by following your mentioned link.Thanks a lot . – Talha Mir Jan 24 '13 at 05:32