I'm new to Android development, and this webview and webview client are killing me. This is my scenario:
- I need to load a webpage containing the social facebook plugin (used to comment on this particular url) and I use WebView for it.
- When a user clicks on a comment via Facebook, he / she should be presented with the login page for the same web view (instead of opening the default browser).
- And as soon as the login is successful, the first page will be displayed (the one that contains the social plugin), allowing the user to comment
What I need to do is emulate the browser workflow, that is, the user, when logged in, is automatically granted permission to add comments to facebook.
My problem:
I do not know how to get all authentication from the browser and redirect it back to my application. I want the whole process to run in my application web browser, and not in the default browser.
I checked all the questions and most of them are advised to use the open source Facebook plugins like Facebook connect and Facebook android SDK. Next, I got information about CookieManager
, CookieSyncManager
, WebViewClient
, WebChromeClient
, but I could not implement my problem. And the closest I found the following:
How to handle facebook as a confirmation in the Android web browser.
So, if you could point me in the right direction, I would be very happy. I'm still trying to figure out how to do all the actions in the webview, and if anything comes up, I will definitely post.
Thanks in advance
Update
I could only implement facebook
login, but could not implement AOL
, Hotmail
and Yahoo
login. To login facebook
just create a custom WebViewClient and by the method shouldOverrideUrlLoading
if(url.contains("https://www.facebook.com/connect/window_comm.php")){ webView.clearHistory(); webView.loadUrl(remoteUrl); } return false;
To allow multiple logins, I did the following technique, but it doesn’t work
if(url.contains("https://www.facebook.com/connect/window_comm.php")){ String cookieString = cookieManager.getCookie("facebook.com"); if(cookieString != null){ cookieManager.setCookie("remoteUrldomain.com", cookieString); CookieSyncManager.getInstance().sync(); webView.clearHistory(); webView.loadUrl(remoteUrl); } } return false;
I am still doing my best to find a solution, and anyone who is there will lead me in the right direction, which would be grateful. thanks in advance