Android Tutorial | Firebase User Registration | Part 2

in #utopian-io8 years ago (edited)

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


resource-card-default-android.jpg

Image Source


Useful Links

Android Developer

Android Open Source Project

Firebase Console


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.

1.png

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.

2.png

Select target device and minimum sdk. I select Api 15 Android 4.0.3 .

3.png

Select Empty Activity and click the next button.

4.png

You do not have to make any changes. To create our project click finish button.

5.png

Our project has been successfully created.

Now open firebase console. And create new project.

6.png

Click new project (plus) button.

8.png

Enter the name of your project. And click the "create project" button to create the project.

9.png

Our FireBase project is ready for use.

Now click Add firebase to your android app.

10.png

You will see the following screen.

11.png

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".

13.png

Okay, paste the package name we copied above and write a name after that click on the "add app" button.

14.png

Now, download google-services.json and move into our Android app module root directory.

15.png

16.png

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'

17.png

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'

18.png

Finally, just click sync now on the android studio.

Okay click finish button on Firebase.

19.png

20.png

Our application has been successfully added to FireBase.

Now click the "Authentication" section.

1.png

2.png

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.

4.png

Click enable and save button for e-mail.

5.png

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'

6.png

And press Sync Now to update the project.

Now, open the "app/manifest/ " folder in our AndroidManifest.xml file.

7.png

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>


8.png

9.png


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.

10.png

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);


12.png

Now we will add an implements to the main class.

Code:


implements View.OnClickListener

@Override

public void onClick(View view) {

}

}


13.png

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

}


14.png

We came to the end of our Part 2 tutorial. Thank you for your attention.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

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.

1UP-Kayrex_tiny.png

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

  • WOW WOW WOW People loved what you did here. GREAT JOB!
  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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?

Coin Marketplace

STEEM 0.05
TRX 0.32
JST 0.081
BTC 63253.25
ETH 1685.08
USDT 1.00
SBD 0.42