0

i am enclosing the code of the Java file, dependency file and Manifestfile

i declared outside

 private static final int MY_REQUEST_CODE = 123;
    List<AuthUI.IdpConfig> providers = Arrays.asList(
            new AuthUI.IdpConfig.PhoneBuilder().build(),
            new AuthUI.IdpConfig.FacebookBuilder().build(),
            new AuthUI.IdpConfig.EmailBuilder().build(),
            new AuthUI.IdpConfig.GoogleBuilder().build(),
            new AuthUI.IdpConfig.TwitterBuilder().build());

after this i mentioned this

 Intent intent = AuthUI.getInstance()
                .createSignInIntentBuilder()
                .setAvailableProviders(providers)
                .setLogo(R.drawable.logo)
                .setTheme(R.style.LoginTheme)
                .setTosAndPrivacyPolicyUrls(
                                        "https://example.com/terms.html",
                                "https://example.com/privacy.html")
                .build();

and the last i mention the startActivity

startActivityForResult(intent,MY_REQUEST_CODE);

now this is my Dependencies File

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'  //1.0.2
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    //Firebase
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.firebaseui:firebase-ui-auth:6.2.0'

    //Facebook
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
    implementation 'com.facebook.android:facebook-android-sdk:5.15.1'

    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    implementation 'com.google.firebase:firebase-auth:19.3.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    //Cardview and Material
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.material:material:1.1.0' //1.1.0

    //button
    implementation 'info.hoang8f:fbutton:1.0.5'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
}

after this it is my Manifest file

  <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".Geo_Activity"/>
        <activity android:name=".Profile" />
        <activity android:name=".HomeActivity" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <meta-data android:name="com.facebook.sdk.ApplicationId"
            tools:replace="android:value"
            android:value="@string/facebook_app_id" />

        <activity android:name="com.facebook.FacebookActivity"
            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>

    </application>

now the problem is that when I add the Facebuilder().build() line into my array list the app is crashed

this is the output screen Output

Kasım Özdemir
  • 5,414
  • 3
  • 18
  • 35
Anurag Tiwari
  • 115
  • 1
  • 10

1 Answers1

1

Change your dependencies to :

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'  //1.0.2
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

//Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.firebaseui:firebase-ui-auth:6.2.1'

//Facebook

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



testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//Cardview and Material
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0' //1.1.0

//button
implementation 'info.hoang8f:fbutton:1.0.5'
implementation 'com.google.android.gms:play-services-location:17.0.0'

Edit :

Add these two strng resources to your strngs :

    <string name="facebook_application_id" translatable="false">APP_ID</string>
<!-- Facebook Application ID, prefixed by 'fb'. Enables Chrome Custom tabs. -->
<string name="facebook_login_protocol_scheme" translatable="false">fbAPP_ID</string>

If you run the app, It will work now, but clicking the facebook button won't get the user authenticated until you get the app id and scheme

To get the app id, log into your facebook account, visit the developers page https://developers.facebook.com/ Create an app there, then add the 'facebook login' and then follow the instructions given. You will find your app id in the top of the page of your facebook app

Just two notes :

  • You need copy the 'OAuth Redirect URI' from the firebase console page(the link given when enabling facebook authentication) to the settings of your facebook app

  • You will need the 'Key hash' which you can be obtained as described here https://stackoverflow.com/a/25524657/9006761 You will then copy it to your facebook app settings

Edit : Scheme is just app id prefixed by 'fb'

ahmed osama
  • 560
  • 1
  • 7
  • 13
  • i got this error.................>>>>java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.demotask/com.example.demotask.MainActivity}: java.lang.IllegalStateException: Facebook provider unconfigured. Make sure to add a `facebook_application_id` string. See the docs for more info: https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#facebook – Anurag Tiwari Apr 22 '20 at 19:36
  • Come on man ! why didn't you post that earlier ?!! I will edit the answer – ahmed osama Apr 22 '20 at 19:39
  • sorry for that pardon me – Anurag Tiwari Apr 22 '20 at 19:41
  • added strings into strings.xml and added Oauth into facebook settings but again it is not working – Anurag Tiwari Apr 22 '20 at 20:07
  • add the strings again, I changed scheme string to be the app id prefixed by 'fb' – ahmed osama Apr 22 '20 at 20:13
  • Thank you So so much for helping me. – Anurag Tiwari Apr 22 '20 at 20:20
  • 1
    Look documentation here https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#facebook – ahmed osama Apr 22 '20 at 20:26
  • Sir i want to add Text on the above of the Logo in the photo include by me – Anurag Tiwari Apr 22 '20 at 20:30
  • You need to define your custom layout as described here https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#custom-layout – ahmed osama Apr 22 '20 at 20:51
  • please sir help me out in this post https://stackoverflow.com/questions/61386532/i-am-using-firebaseui-multiple-login-method-but-how-to-give-permissions-to-every – Anurag Tiwari Apr 23 '20 at 14:59