Firebase Examples   Firebase Auth   Firebase Database   Firebase Firebase Features of Firebase Firebase comes with bunch  features  essentia...

Firebase Auth

12:39 2 Comments


Firebase Examples Firebase Auth Firebase Database Firebase

Firebase

Features of Firebase

Firebase comes with bunch features essential for every android app starting from authentication to hosting the app.
google firebase android features
Below are the advantages using Firebase in general:
> Super easy and quick to implement.
> No server side configuration needed. No PHP Scripts and No Database Designs.
> Realtime update without using GCM.
> Autoscaling built-in
> Can start for free (only need to start paying once we hit 50 connections)
> Robust APIs for Javascript (including several frameworks like Angular), iOS, and Android
> Built-in support for authentication services like Facebook, Google, and Twitter
> Declarative Security Rules model allows us to enforce read/write privileges and data validation throughout the tree
Some of the disadvantages of Firebase can be sum up in the following:
> Need to build indexes manually
> May need to build “event log” manually as well (in separate sub-tree?)
> Implementation of REST API could be difficult on embedded platforms
> Data validation rules do not support complex objects directly (you’d need to validate individual child nodes separately)

1. Enabling Firebase Auth

1. First thing you need to do is go to https://firebase.google.com/ and make an account to gain access to their console. After you gain access to the console you can start by creating your first project.
2. Give the package name of your project (mine is info.androidhive.firebase) in which you are going to integrate the Firebase. Here the google-services.json file will be downloaded when you press add app button.
3. Next go to your project dashboard. Find the Auth and click get started. Go to set up sign in method and choose Email & Password and enable it.
android-adding-firebase-to-your-project
Now we are ready to start with our Android project. We are going to create a simple app which contains firebase authentication and profile management. Overall we are going to see how to add LoginRegistrationForgot PasswordChange EmailChange Password & finally Sign Out option.

2. Creating Android Project

1. Create a new project in Android Studio from File ⇒ New Project. When it prompts you to select the default activity, select Blank Activity and proceed.
While filling the project details, use the same package name which you gave in firebase console. In my case I am using same info.androidhive.firebase.
2. Open AndroidManifest.xml and add the INTERNET permission as we need to make network calls.
<uses-permission android:name="android.permission.INTERNET" />
3. Paste the google-services.json file to your project’s app folder. This step is very important as your project won’t build without this file.
4. Now open the build.gradle located in project’s home directory and add firebase dependency.
build.gradle
dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
5. Open app/build.gradle and add firebase auth dependency. At the very bottom of the file, add apply plugin: ‘com.google.gms.google-services’
app/build.gradle
dependencies {
    compile "com.google.firebase:firebase-auth:9.0.2"
}
apply plugin: 'com.google.gms.google-services'

activity_main.xml :

<LinerLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orieation="vericatail"
   android:gravity="center"/>


<LinerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orieation="vericatail"
    android:gravity="center">
    <Editext
      android:id="@+id/emailid"
      android::layout_width="match_parent"
      android:layout_height="warp_content"
      android:hint="Enter your emailid"
      android:hintColor="#ffffff"
      android:textColor="#0000ff"
      android:textSize="14sp"
      />


    <Editext
      android:id="@+id/password"
      android::layout_width="match_parent"
      android:layout_height="warp_content"
      android:hint="Enter your password"
      android:hintColor="#ffffff"
      android:textColor="#0000ff"
      android:textSize="14sp"
      />


      <Button
        android:id="@+id/login"
        android::layout_width="match_parent"
        android:layout_height="warp_content"
        android:textSize="14sp"
        android:textColor="#ffffff"
        android:text="Login"
        android:background="0000ff"
        />


    </LinerLayout>
   </LinerLayout>

MainActivty:

package nwallpapers.com.neo.istone.andro.project.wallpapers.nwallpapers;
import android.annotation.SuppressLint;import android.app.Activity;import android.app.ProgressDialog;import android.content.Context;import android.content.DialogInterface;import android.content.Intent;import android.content.SharedPreferences;import android.graphics.Color;import android.graphics.drawable.GradientDrawable;import android.os.Build;import android.support.annotation.NonNull;import android.support.annotation.RequiresApi;import android.support.v7.app.AlertDialog;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.AutoCompleteTextView;import android.widget.Button;import android.widget.EditText;import android.widget.LinearLayout;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;
import java.util.Timer;import java.util.TimerTask;
public class Login extends Activity {

private AutoCompleteTextView email; private EditText password; private Button login_btn; private TextView rest,creating_new_account; private FirebaseAuth mAuth; private LinearLayout main; private SharedPreferences new_users; private SharedPreferences data_expoerting; private AlertDialog.Builder dialog; private AlertDialog.Builder show; private Timer timer = new Timer(); private TimerTask _timer;
public Login() {
}

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState ); setContentView( R.layout.activity_main );
      email = findViewById(R.id.email);
      main = findViewById(R.id.main);      password = findViewById(R.id.password);      login_btn = findViewById(R.id.login_btn);
       login_btn.setOnClickListener(new View.OnClickListener() {
    @Override
public void onClick(View v) {
if (email.getText().toString().contains( "@" )) {
if (email.getText().toString().equals( "" ) && password.getText().toString().equals( "" )) {
Toast.makeText( Login.this, "Fill it", Toast.LENGTH_SHORT ).show(); } else {
login();
}
});
}
    private void login() {
      if (email.getText().toString().equals("")){
neoistone.Toast(this,"Enter your message"); } else {
if (password.getText().toString().equals( "" )) {
neoistone.Toast( this, "Enter your Pswword" ); } else {
final ProgressDialog progressDialog = new ProgressDialog( Login.this ); progressDialog.setMax( 100 ); progressDialog.setMessage( "Please Wait Login you ..." ); progressDialog.setIndeterminate( true ); progressDialog.setCanceledOnTouchOutside( false ); progressDialog.show(); mAuth = FirebaseAuth.getInstance(); mAuth.signInWithEmailAndPassword( email.getText().toString(), password.getText().toString() )
.addOnCompleteListener( this, new OnCompleteListener<AuthResult>() {
@Override public void onComplete(@NonNull Task<AuthResult> task) {
final String error = task.getException() != null ? task.getException().getMessage() : "";
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information new_users.edit().putString( "new", "123" ).apply(); data_expoerting.edit().putString( "email", mAuth.getCurrentUser().getEmail().toLowerCase().toString() ).apply(); // progress bar dismiss// progressDialog.dismiss(); neoistone.Toast(Login.this,"Loged");
} else {
// If sign in fails, display a message to the user. neoistone.Toast(Login.this,"error is :-"+error); progressDialog.dismiss(); }

// ... }
} ); }
}
}
}


2.resetPassword :



mAuth.getInstance().sendPasswordResetEmail(emailid.getText().toString());




Following On Google + or youtube channal
Google plus: Join Now
whatsapp: group:- Join Whatsapp group
youtube channal:- Neo-istone youtube channal

2 comments: