facebook login not working in andoroid webview (it redirects to mobile browser)

416
May 01, 2017, at 09:30 AM

I am developing a webview app for my website which contains facebook login. Whenever I tried to login facebook through my webview app it redirects to mobile browser. I think it is because facebook opens new window for login and my android webview supports only one window .I think Making facebook login work with an Android Webview is the similar question but i am not able to modify my source code using this one

here is my code for

MyAppWebViewClient.java

public class MyAppWebViewClient extends WebViewClient {
        List<String> whiteHosts = Arrays.asList("example.com",  "whatsapp.com", "m.facebook.com",  "facebook.com");
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            String host = Uri.parse(url).getHost();
            if(whiteHosts.contains(host)) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        }
    }    

which proves I can open facebook.com in my webview app

MainActivity.java

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.webkit.URLUtil;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends Activity {
    private WebView mWebView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        mWebView = (WebView) findViewById(R.id.activity_main_webview);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.getSettings().setDomStorageEnabled(true);
        mWebView.loadUrl("http://example.com/");
        mWebView.setWebViewClient(new com.example.appname.MyAppWebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                //hide loading image
                findViewById(R.id.progressBar1).setVisibility(View.GONE);
                //show webview
                findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);
            }
        }
        );
    }
    @Override
    public void onBackPressed() {
        if(mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if( URLUtil.isNetworkUrl(url) ) {
            return false;
        }
        // Otherwise allow the OS to handle it
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity( intent );
        return true;
    }   

It will be huge help if someone could give me modified code with working facebook login into my webview app

thanks in advance

READ ALSO
Android MediaPlayer not playing mp4 video pre Lollipop

Android MediaPlayer not playing mp4 video pre Lollipop

I'm trying to play an mp4 video rendered on a TextureView, it's working on API LEVEL >= 21 (after Lollipop), but on previous versions it's not playingI'm getting the following error in the logcat: error (1, -2147483648)

348
adobe animate sounds not working on phonegap

adobe animate sounds not working on phonegap

I have build a html5 android app with Adobe animate cc, every thing work perfectly on browser, but when I build using phoneGap I lose sounds

317
Implement Crop Bottom into TouchImageView Library

Implement Crop Bottom into TouchImageView Library

I am trying to implement TopCropImageView() https://gistgithub

352