I am newbie to Android development and this webview and webview client is killing me. This is my scenario:
- I have to load a web page which contains facebook social plugin (used for commenting on that particular url) and I am using WebView for it
- When user clicks comment using Facebook, he/she is to be given login page on same webview (instead of opening default browser)
- And once the login is successful, the first page (the one containing social plugin) is to be displayed allowing user to comment
What I have to do is emulate the working process of browser i.e. the user when logs in, he/she is automatically granted permission to add facebook comment.
My problem:
I don't know how to get all the authentication from browser and redirect it back to my app webview. What I want is to do all the process in my app webview rather than going to default browser.
I have checked all the stack overflow questions and most of them advise on using open source Facebook plugins like Facebook connect and Facebook android SDK. Further I got some info on CookieManager
, CookieSyncManager
, WebViewClient
, WebChromeClient
but I couldn't implement on my issue. And the closest I found is this:
How to handle facebook like with confirm in android webview
So folks if you could point me in the right direction, I would be very glad. I am still trying to understand on how to make all the action on a webview and if anything comes I will surely post.
Thanks in advance
Update
I could only implement facebook
login but couldn't implement AOL
,Hotmail
and Yahoo
login. For facebook
login just create a custom WebViewClient and on method shouldOverrideUrlLoading
if(url.contains("https://www.facebook.com/connect/window_comm.php")){
webView.clearHistory();
webView.loadUrl(remoteUrl);
}
return false;
To allow multiple login I have implemented 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 the solution, and anybody out there would guide me in proper direction that would be grateful . Thanks in advance