I'm trying to make facebook like functionality in Android WebView (project specification does not allow browser opening, or any out of application activity).
So, restrictions are that it has to be done in WebView. I've managed to make it a dialog, and apon user's click like button, it (the WebView) redirects successfully (in the same view) to facebooks login page. After successful authentication, the WebView
(in a dialog) is redirected to blank page with facebook header.
Interestingly enough, when user leaves the blank dialog and click again on the like button it works like perfectly (like and unlike) - it somehow keeps authentication active. To resolve the blank page, I've tried/used following:
- using
WebViewClient
and shouldOverloadUrlForwarding
to keep whole process in same WebView
dialog.
- using
WebChromeClient
to properly execute JavaScript - without it after login is not possible to like/unlike.
- tried using
setUserAgentString()
to simulate other browsers like Chrome or Firefox
tried the SSL Error certificate handling (in API level 8) (at WebViewClient
)
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
using (and all possible combination of these)
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
Tried also persisting cookies with CookieSyncManager
, CookieManager
and manually handling.
All of this was with no result. I really appreciate any help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…