Skip to main content

Working with Google Firebase Part-2

Hello guys, In 1st part of this series we work with setup our android app on Firebase console. In this part we will work with project structure and coding part.What we do in this :-
We will work with--  1: Signup
                                   2: Login
                                   3: Retrieve password



Hope you have setup your project. Project structure should be like this:




Add permission of Internet in you manifest.
               <uses-permission android:name="android.permission.INTERNET" />

Add below line in you build.gradle(picture-1) dependencies
        compile "com.google.firebase:firebase-auth:9.2.0"

Add below line in you build.gradle(picture-1) in last
        apply plugin: 'com.google.gms.google-services'

Add below line in you app-gradle(picture-2) dependencies
       classpath 'com.google.gms:google-services:3.0.0'

Now in onCreate(...) method of your Activity(in my case MainActivity), create an instance of
FirebaseAuth.With this auth instance, you can do the task of signup, login, password retrieve,
 change password, change your email etc. like this :

                    FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();

SignUp :

firebaseAuth.createUserWithEmailAndPassword("your email",
        "your password").addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override   
            public void onComplete(@NonNull Task<AuthResult> task) {
                   if (!task.isSuccessful()) {
                      Snackbar.make(etEmail, "Unable to register...", Snackbar.LENGTH_SHORT)
                      .show();
                    return;
        }
        Toast.makeText(MainActivity.this, "Successfully registered...", Toast.LENGTH_SHORT)
        .show();
    }
});

Login :

firebaseAuth.signInWithEmailAndPassword("your email",
 "your password").addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override          
            public void onComplete(@NonNull Task<AuthResult> task) {
                 if (!task.isSuccessful()) {
                    Snackbar.make(etEmail, "You may not registered. Please Create        account first",
                    Snackbar.LENGTH_SHORT).show();
                    return;
                }
                Toast.makeText(LoginActivity.this, "Successfully login...", Toast.LENGTH_SHORT)
                .show();
            }
        });

Retrive Password :

firebaseAuth.sendPasswordResetEmail("your email").addOnCompleteListener(new OnCompleteListener<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {
        if (!task.isSuccessful()) {
            Snackbar.make(etEmail, "Unable to send password reset email",                 Snackbar.LENGTH_SHORT).show();
            return;
        }
        Snackbar.make(etEmail, "Password reset email has been send to you email id." +
                " Please follow the link and reset your password", Snackbar.LENGTH_SHORT).show();
    }
});

This is all about Google Firebase Authentication. In my next blog i will post tutorial for Push Notification using Firebase. and SOURCE CODE of firebase authentication and firebase push notification both.

Suggestions are most welcome. Please keep reading my blog and share to your friends :)





Comments

Popular posts from this blog

Working with MPAndroidChart (how to create Bar Chart using MPAndroidChart)

Hi Friends, In this tutorial i am going to show, "How to create Bar Chart using MPAndroidChart". There is a lot of libraries for creating charts in android like AChartEngine, MpAndroidChart, AndroidPlot etc. Your first question may be, Why MPAndroidChart. So MpAndroidChart provides better animation functionality and easy to use in comparision. Using  MPAndroidChart library  we can draw a: ·          Simple Bar Chart ·          Grouped Bar Chart ·          Horizontal Bar Chart ·          Simple Line Chart ·          Line Chart with Cubic Lines ·          Grouped Line Chart ·          Combined Line and Bar Chart ·          Pie Chart ·          Scatter Chart ·          Candlestick Chart ·          Radar Chart Here we will create Simple Bar Chart with multiple color based on ranging. Ok We start with coding part now. First of all create your project in Android Studio and add gradle dependency for  MPAndroidChart library  into y

JavaFX WebView- Creating Browser Sample

Hi Friends, In this post, i am going to give an overview about JavaFX WebView . This is an embedded browser component which is based on WebKit . If allow you to use Css, JavaScript, HTML5 and more to customise your embedded browser. The embedded browser enables you to perform the following tasks in your JavaFX applications: Render HTML content from local and remote URLs Obtain Web history Execute JavaScript commands Perform upcalls from JavaScript to JavaFX Manage web pop-up windows Apply effects to the embedded browser  I am going to provide and explain you a sample example to create your embedded browser. This is a JavaFX sample example. if you want to take an introduction about JavaFX please visit my previous blog . I have use IntelliJ Idea IDE for this example. You can visit this link  to understand how to create JavaFX application. I am attaching the project structure image below- In this sample- we have two java class. First

Java Socket Basics(Socket Programming in Java) Part-2(UDP)

Hi friends, We are going to discuss about UDP Socket Programming . In previous post  we discussed about the differences between TCP & UDP and the sample example of TCP Socket Programming. Below is the sample example of chat application using UDP  Socket Programming . UDP Sample :-  We are going to create an small example which contains two classes. UdpServer.java:-  This is a server class. Means this class will serve the purpose of socket connection. DatagramSocket is the java class and serve the purpose of Server and Client both. The overloaded constructor of DatagramSocket class matters. DatagramPacket is the java class which is responsible to transmit the data/packet over the network from server to client and vice-versa. UdpClient.java:-  This is client class. This serves the purpose of client which will communicate to server and send data to server and receive the data sent by server. UdpServer.java import java.net.DatagramPacket ; import java.net.Datag