Signin using facebook sdk in android when facebook app not installed issue

Issue

I have implemented login via facebook in android app and it is working fine when facebook app is installed on my device. after uninstalling the app, when hit login via facebook, it shows the facebook login screen, after granting permission for the app, it redirects me to the my login screen, but onActivityResult is not called, and I can’t click on any button in the screen. when I hit on back button, a transparent screen is closed, and onActicityResult is called with intent null.

In my gradle file I’m using the latest facebook version

implementation 'com.facebook.android:facebook-android-sdk:12.0.0

And this is the code I’m using in my activity:

 mCallbackManager = CallbackManager.Factory.create();
 
LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                performFBLogin(loginResult);
            }

            @Override
            public void onCancel() {
                showErrorMessage(getResources().getString(R.string.facebook_login_canceled), true);
            }

            @Override
            public void onError(@NonNull FacebookException exception) {
                showErrorMessage(exception.getLocalizedMessage(), true);
            }
        });

And the click event is done like following:

        LoginManager.getInstance().logInWithReadPermissions(this, mCallbackManager, Arrays.asList("public_profile", "email"));

My manifest file looks like this:

  <activity
            android:name="com.facebook.CustomTabMainActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name" />
        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>


  <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" /> 
        <!-- [Facebook] -->
        <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>

Anyone face an issue like this?

Thanks

Solution

This is a bug in Facebook’s SDK when working with AndroidX fragments / activity with version 1.5.0+

https://github.com/facebook/facebook-android-sdk/blob/main/CHANGELOG.md#1411

Just update your Facebook SDK to the latest version (recommended) OR downgrade your fragment / activity version (not recommended)

Answered By – jos_fzr

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published