How to add firebase authentication in android app [Java/Kotlin]

Well, if minimal is what you like best then it is for you. Without much ado let's start to add Firebase authentication to your app.

     Firebase Authentication is the best quick authentication technique used to login users to an Android app. It is very easy to set up and requires a very minimal amount of coding. It only has one disadvantage. It does not allow you to edit the login screen. You can only put logo with privacy settings and Terms and conditions link on your login screen. Well, if minimal is what you like best then it is for you. Without much ado let's start to add Firebase authentication to your app.
[post_ads]

How to add firebase authentication in android app

How to add firebase authentication in android app

First, add these Gradle dependencies in your app-level Gradle.

[implementation 'com.google.firebase:firebase-core:17.0.1' implementation 'com.firebaseui:firebase-ui-auth:5.0.0' implementation 'com.google.android.gms:play-services-auth:17.0.0' implementation 'com.facebook.android:facebook-android-sdk:5.2.0' ]

Now Sync your Gradle. Add facebook dependency only if you want to add facebook login to your app. Now import this statements in your main.activity.

[import com.firebase.ui.auth.AuthUI; import com.firebase.ui.auth.IdpResponse; import com.google.firebase.FirebaseApp; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; ]

How to add firebase authentication in android app

Now go to Firebase Console and make a new project. Enter the name of your project, tick all the boxes and click on Accept.

How to add firebase authentication in android app

 Click on Android Icon to add your android app to your project.

How to add firebase authentication in android app

Enter the details of your android app by entering details like app name, package name and SHA1 signature.

How to add firebase authentication in android app

You can find a SHA1 signature in signing the report of your app.
[post_ads_2]
Once you click on register you will be asked to download google-services.json. Paste it in the root directory of your app.

Initialize this variable in your main activity class.

[private static final int RC_SIGN_IN = 1;]

In your onCreate() method  initialize firebase.

[FirebaseApp.initializeApp(this);]

In your Main Activity class, create a signInIntent.

[public void createSignInIntent() {
    List<AuthUI.IdpConfig> providers = Arrays.asList(
            new AuthUI.IdpConfig.GoogleBuilder().build(),
            new AuthUI.IdpConfig.FacebookBuilder().build());
    startActivityForResult(
            AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setAvailableProviders(providers)
                    .setTosAndPrivacyPolicyUrls(
                            "YOUR TOS URL",
                            "YOUR PRIVACY POLICY URL")
                    .setLogo(R.drawable.my_great_logo)
                    .setTheme(R.style.Mytheme)
                    .build(),
            RC_SIGN_IN);
}]

In .setlogo you can set your logo for showing logo on your sign in screen. Now create an onActivityResult() intent.

[@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        IdpResponse response = IdpResponse.fromResultIntent(data);
        if (resultCode == RESULT_OK) {
            // Successfully signed in
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            Toast.makeText(this, user.getDisplayName(), Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "Sign in error", Toast.LENGTH_SHORT).show();
        }
    }
}]

Then create onstart() method.

[@Override
protected void onStart() {
    FirebaseApp.initializeApp(MainActivity.this);
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user==null){
        createSignInIntent();
    } else {
        //Already signed in
        Toast.makeText(this, user.getDisplayName(), Toast.LENGTH_SHORT).show();
    }
    super.onStart();
}]

Thats it. You have successfully added firebase login to your app. 

COMMENTS

BLOGGER
Name

Affiliate marketing tutorial,2,Android,60,Android Development,22,Android tutorials,41,Blogging tactics,8,Deals,1,DSA,4,Elite Youtube Tutorial,4,Firebase,1,Flutter,4,Fuchsia,1,Hosting Guides,3,Leetcode,4,Miscellaneous,10,Mobile Gaming,17,NTN,94,Problogging,7,PUBG,16,Reviews,1,SEO Tutorial,5,Start a blog,9,Start a channel,6,Top 5,4,Travel Blogging,4,Windows,12,Windows Security,4,Windows tutorials,7,Wordpress Tutorials,4,Youtube Tutorials,11,
ltr
item
A Passionate Developers Creation: How to add firebase authentication in android app [Java/Kotlin]
How to add firebase authentication in android app [Java/Kotlin]
Well, if minimal is what you like best then it is for you. Without much ado let's start to add Firebase authentication to your app.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLygVELdkfshlwSGjtsDCEh0GezoItkPugQc3IaDhfRSy8PP0Bm4WXZ90digcub72FNfhYzsaJolrcfDdu237UAgQbilNB37XqD3f59Cpf45cixCkEnYpUNKJ0XqCB2-1sHhCiZWx_h_E/s320/WhatsApp+Image+2019-08-13+at+8.36.59+PM.jpeg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLygVELdkfshlwSGjtsDCEh0GezoItkPugQc3IaDhfRSy8PP0Bm4WXZ90digcub72FNfhYzsaJolrcfDdu237UAgQbilNB37XqD3f59Cpf45cixCkEnYpUNKJ0XqCB2-1sHhCiZWx_h_E/s72-c/WhatsApp+Image+2019-08-13+at+8.36.59+PM.jpeg
A Passionate Developers Creation
https://www.apdevc.com/2019/08/how-to-add-firebase-authentication-in.html
https://www.apdevc.com/
https://www.apdevc.com/
https://www.apdevc.com/2019/08/how-to-add-firebase-authentication-in.html
true
3690156770086819421
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content