I am working on an Android app for an existing php website. The website has a login path via Facebook and once the users log in, they get redirected to the main page. The problem comes when I want to login on my app (I've already created the app with a webview to be able to see the website inside the app). Now, the problem comes when I click on the button for login(using the app). In the website everything works well. However, in the webview, after introducing my info into the inputs, the screen gets white and even though I wait or close the app and open it again, when I press the button to login, that white screen appears. I guess it's because of the pop up that gets open to log the user into Facebook, and then, into the website. However, how could I solve that problem? I'm NOT using the Facebook login button, but my own. Is there a way to avoid opening the pop up, open the link into an iframe or whatever, and once the response is affirmative for login, close that iframe/whatever and redirect the user to main.php? I'm freaking out right now because I cannot find any answer in Stack Overflow for this specific problem. Thanks beforehand!
Asked
Active
Viewed 2,152 times
1
-
Check this .. You have to handle the popup manually..http://stackoverflow.com/questions/12648099/making-facebook-login-work-with-an-android-webview/19068076#19068076 – Sunil Sunny May 30 '16 at 05:48
-
Thank you! Lamentably, the link's content couldn't help me out. – Criss May 30 '16 at 06:02
-
What was the issue ? – Sunil Sunny May 30 '16 at 06:14
-
Those codes in the link are totally different from what I have and need. I need to avoid facebook pop up into my webview. Because first an auto_blank gets open, then another one with a redirection, and then the login finishes. For a webview, it's not good at all. I need to open those pop ups into a section or something like that so that when the authentication of facebook is done, the user gets redirected to main.php and I avoid the problem of several pop ups inside the webview. How can I do that? – Criss May 30 '16 at 06:22
1 Answers
0
I don't know if this help's you. Please try this.
String redirect_uri = "https://m.facebook.com/v2.1/dialog/oauth/read";
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String host = Uri.parse(url).getHost();
if(host.equals("m.facebook.com") || host.equals("www.facebook.com")){
return false;
}else {
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.INVISIBLE);
if (url.startsWith(redirect_uri)) {
mWebviewPop.loadUrl(url_with _fblogin);
new CountDownTimer(4000,4000) { // giving the webview a 4s delay to complete the process.
@Override
public void onTick(long l) {
}
@Override
public void onFinish() {
if(mWebviewPop != null){
mWebviewPop.setVisibility(View.GONE);
mContainer.removeView(mWebviewPop);
mWebviewPop=null;
mWebview.loadUrl(url_with _fblogin); // mWebview is the orginal webview.
}
}
} .start();
}
super.onPageFinished(view, url);
}
Create an onCreateWindow to handle the popup like this Making facebook login work with an Android Webview .Here mWebviewPop is the webview of onCreateWindow. Hope this helps.
Community
- 1
- 1
Sunil Sunny
- 3,949
- 4
- 23
- 53