Android Tutorial | Firebase User Registration | Part 2
Android is a mobile operating system developed by Google, based on a modified version of the Linux kernel and other open source software and designed primarily for touchscreen mobile devices such as smartphones and tablets. In addition, Google has further developed Android TV for televisions, Android Auto for cars, and Android Wear for wrist watches, each with a specialized user interface. Variants of Android are also used on game consoles, digital cameras, PCs and other electronics. Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment.
Source
Source 2
Useful Links
What Will I Learn?
Create Android Project (in Android Studio)
Android Firebase Integreation
Android Internet Permission
Requirements
Android Studio (Download)
Basic knowledge of Java
Android Device (For run and test our app)
Difficulty
- Intermediate
Curriculum
Android Tutorial | Google Text Recognition API | Part 1
Tutorial Contents
In this tutorial I will show you how to integrate FireBase into android project. For this I will prepare a registration page in our app.
Firebase has a lot of free features, but today we will use the Auth section in our android project.
More Info Firebase
First, we need to create new project on Android studio.
We are opening a new project on android studio. Write the name of our application and the project location, and we click the next button.
Select target device and minimum sdk. I select Api 15 Android 4.0.3 .
Select Empty Activity and click the next button.
You do not have to make any changes. To create our project click finish button.
Our project has been successfully created.
Now open firebase console. And create new project.
Click new project (plus) button.
Enter the name of your project. And click the "create project" button to create the project.
Our FireBase project is ready for use.
Now click Add firebase to your android app.
You will see the following screen.
First of all we need to enter the package name of our application. For this open Gradle Script's section "build.gradle (Module: app)" file and copy "applicationId".
Okay, paste the package name we copied above and write a name after that click on the "add app" button.
Now, download google-services.json and move into our Android app module root directory.
Now we need to edit our grade files. First open build.gradle (Project) and add this line.
classpath 'com.google.gms:google-services:3.2.0'
Okay now open the build.gradle (Module:app) and add this lines.
compile 'com.google.firebase:firebase-core:11.8.0'
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
Finally, just click sync now on the android studio.
Okay click finish button on Firebase.
Our application has been successfully added to FireBase.
Now click the "Authentication" section.
Okay now, click the "Set-up sign-in method" button.
You can use e-mail for registration and login as well as facebook, twitter, phone. I will only use e-mail for now, so I will open it for this.
Click enable and save button for e-mail.
Now, open Gradle Script's section "build.gradle (Module: app)" file. And add this code.
Code
compile 'com.google.firebase:firebase-auth:11.8.0'
And press Sync Now to update the project.
Now, open the "app/manifest/ " folder in our AndroidManifest.xml file.
We will define a permission to use our android device's Internet.
Internet permission Code:
<uses-permission android:name="android.permission.INTERNET"/>
Now we can go into the design of our application, open the "app/res/layout/ " folder in our activity_main.xml file. Let's go to the "text" (coding) section below. And write the code of our application's design.
I've added a linear layout first. I inserted one button, two edittext and one textview into this linear layout.
Code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<EditText
android:id="@+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter Your Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/editTextPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter Your Password"
android:inputType="textPassword" />
<Button
android:id="@+id/registerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Register"/>
<TextView
android:id="@+id/signInTextview"
android:text="Sign In"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"/>
</LinearLayout>
The design of our application has been completed. I chose to do a simple design. You can design it as you like.
Now let's go coding MainActivity open the "app/java/projectname/ " folder in our MainActivity.java file.
We will first define the necessary objects and we will import our libraries for these objects.
Code:
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
private Button buttonRegister;
private EditText editTextEmail;
private EditText editTextPass;
private TextView textviewSignIn;
buttonRegister = (Button) findViewById(R.id.registerButton);
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
editTextPass = (EditText) findViewById(R.id.editTextPass);
textviewSignIn= (TextView) findViewById(R.id.signInTextview);
Now we will add an implements to the main class.
Code:
implements View.OnClickListener
@Override
public void onClick(View view) {
}
}
Now we will add our click listeners and write click methods.
Code:
buttonRegister.setOnClickListener(this);
textViewSignIn.setOnClickListener(this);
Methods code:
@Override
public void onClick(View view) {
if (view == buttonRegister) {
registerUser();
}
else if (view == textViewSignIn) {
// Open login activity
}
}
private void registerUser() {
String email = editTextEmail.getText().toString().trim();
String pass = editTextPass.getText().toString().trim();
if(TextUtils.isEmpty(email)){
//email is empty
}
else if (TextUtils.isEmpty(pass)){
//pass is empty
}
// validations okay
}
We came to the end of our Part 2 tutorial. Thank you for your attention.
Posted on Utopian.io - Rewarding Open Source Contributors































Great job a whole lot of Information thanks
Thanks :)
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
@pars11, I like your contribution to open source project, so I upvote to support you.
You've got upvoted by
Utopian-1UP!You can give up to ten 1UP's to Utopian posts every day after they are accepted by a Utopian moderator and before they are upvoted by the official @utopian-io account. Install the @steem-plus browser extension to use 1UP. By following the 1UP-trail using SteemAuto you support great Utopian authors and earn high curation rewards at the same time.
1UP is neither organized nor endorsed by Utopian.io!
Hey @pars11 I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Know how to run IPSF on Android?