You can let your users authenticate with Firebase using their Facebook accounts by integrating Facebook Login into your app. You can integrate Facebook Login either by using the Firebase SDK to carry out the sign-in flow, or by carrying out the Facebook Login flow manually and passing the resulting access token to Firebase. User authentication can be a powerful addition to your Android app. Once you can identify the individual people who are using your app, you can customize your app’s content, potentially delivering an experience that feels as though it was designed with a specific user in mind.
Creating Android Project
Open Android Studio and Click on File-> New ->New Project
Give your application a name (in my case it is AndroidLogin) and a package (mine is net.simplifiedcoding)
Select Phone or Tablet
Select Blank Activity with Fragment.
Leave the rest things as it is and finish.
Now once our project is ready we need to configure a lot of things so lets begin.
Prerequisites for creating Login with Facebook Android App
Facebook app configured and linked to our android app
Facebook App ID
Android Key Hash
Lets start with creating Facebook App
Configuring Facebook SDK to Android Studio
Go to your gradle scripts -> build.gradle(Module:app)
Add the following code
Creating Facebook App
Go to https://developers.facebook.com/. If you have not registered yourself as a developer yet then facebook will ask you to register as a developer. Simply register as a developer. (Congrats you are now a developer :P)
From the top navigation menu hover over my apps.
Then click add a new app.
You will asked to select a platform, click on android.
On the new page you can select quick start or you can select skip and create app id from the upper right corner.
Click on skip and create app id.
Give a display name and a namespace for your app as shown in the image below.
In this Facebook Login example you will learn how to register your application with Facebook and implement Login and logout in your Android Application.
Checking Login Status
Only one Facebook user at a time can be logged in into your app. Also once a user has logged in he is not logged out unless the access token expires. This basically means that the login status remains intact even if the app is killed.
As already mentioned the login status is automatically reflected in the LoginButton. The text on the button automatically changes to “Logout” and button acts as the logout button once the user has logged in. Similarly you need to modify the behavior of your app if the user is already logged in.
In this section we will be checking if the user has already logged in in the onStart() method. If user is already logged in we directly send a request using the saved Access Token and display the details.
We use AccessToken.getCurrentAccessToken() below. This API will return the current access token for the application if the user is logged in. If not it will return null.