Skip to main content

Featured

Game Development Tutorials In Android

Game Development Tutorials In Android Hi Guys,                 We are shortly started Game Development Tutorials in Android Studio. So everyone supports me and share this blogs to your friends. Guys, At this time everyone is freely available to source code and we are provide a video for step by step game developments. you are learn free and feel free to support us. Guys, if you have any question to me, so feel free to comment us. I will try to answer all the question as long as possible.                                                     Thank's                                                                          ...

firebase login for android application

Firebase Login for Android Application Example Source Code


In this Example, You will simply Login Firebase Cloud Database using Android , this is a Live Application Example : 

So, let Start : 

                                                activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.bschandel.indservices.MainActivity">


    <LinearLayout
        android:layout_centerHorizontal="true"
        android:layout_centerVertical = "true"
        android:orientation="vertical"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content" >

        <EditText
            android:layout_margin="15dp"
            android:inputType="textEmailAddress"
            android:hint="Enter your email"
            android:id="@+id/editTextEmail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


        <EditText
            android:layout_margin="15dp"
            android:inputType="textPassword"
            android:hint="Enter your Password"
            android:id="@+id/editTextPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:layout_margin="15dp"
            android:id="@+id/buttonRegister"
            android:text="Register User"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:textAlignment="center"
            android:text="Already Registered? Sign in here"
            android:id="@+id/textViewSignin"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content" />

    </LinearLayout>

</RelativeLayout>




Now we are configure to the Java Main Class : 

                                                       MainActivity.java

package com.example.bschandel.indservices;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button buttonRegister;
    private EditText editTextEmail;
    private EditText editTextPassword;
    private TextView textViewSignin;

    private ProgressDialog progressDialog;
    private FirebaseAuth firebaseAuth;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressDialog = new ProgressDialog(this);
        buttonRegister = (Button)findViewById(R.id.buttonRegister);
        editTextEmail = (EditText) findViewById(R.id.editTextEmail);
        editTextPassword = (EditText)findViewById(R.id.editTextPassword);
        textViewSignin  = (TextView) findViewById(R.id.textViewSignin);

        firebaseAuth = FirebaseAuth.getInstance();
        buttonRegister.setOnClickListener(this);
        textViewSignin.setOnClickListener(this);
    }

    private void registerUser()
    {
        String email = editTextEmail.getText().toString().trim();
        String password = editTextPassword.getText().toString().trim();

        if (TextUtils.isEmpty(email)) {
            //email is empty
            Toast.makeText(this,"Email is Empty, Please Enter Email ",Toast.LENGTH_SHORT).show();
            //stopping the function execution
            return;
        }
        if (TextUtils.isEmpty(password)) {
            //password is empty
            Toast.makeText(this,"Password is Empty, Please Enter a Password",Toast.LENGTH_SHORT).show();
            //stopping the function execution
            return;
        }
        // if validations are ok
        // we will first show a progressDialog
        progressDialog.setMessage("Registering User....");
        progressDialog.show();

        firebaseAuth.createUserWithEmailAndPassword(email,password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()) {
                            Toast.makeText(MainActivity.this,"Registered Successfully",Toast.LENGTH_SHORT).show();
                        }
                        else
                        {
                            Toast.makeText(MainActivity.this,"Could Not Register, Please Try Again!!",Toast.LENGTH_SHORT).show();
                        }
                    }
                });

    }


    @Override
    public void onClick(View view) {
        if(view == buttonRegister) {
            registerUser();
        }
        if(view == textViewSignin)
        {
            //will open login Activity here
        }

    }
}


Now Configure Android Manifest.xml file , simply use this permission

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

And uses this compiler for gradle file : 

compile 'com.google.firebase:firebase-auth:11.4.2'


And also, some dependencies are require for multiple urls , so use 
 
repositories {
                       mavenCentral()
              }

That's it,

Now just copy and paste this code and use it... wherever you want a login activities....





If this information is important to you , and you want to , I will continue writing some more details of Android Programming Language, so click on the advertising, available on this page. This is motivate me for writing some more useful program and Tips, Thank's 

Comments