![]() |
VOOZH | about |
Phone number Firebase Authentication is used to sign in a user by sending an SMS message to the user's phone. The user signs in using a one-time code contained in the SMS message. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language.
Note: All projects utilizing Firebase Phone Authentication (SMS) must be linked to a Cloud Billing account starting from September 1, 2024
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
Note that select Kotlin as the programming language.
Navigate to Gradle Scripts > build.gradle.kts (Module :app) and add the following dependencies
dependencies {
...
implementation ("com.google.firebase:firebase-auth:23.2.0")
implementation ("com.google.android.gms:play-services-auth:21.3.0")
}
In the same file, add the following plugin
plugins {
...
id("com.google.gms.google-services")
}
Navigate to Gradle Scripts > build.gradle.kts (Project :<app name>) and add the following plugin
plugins {
...
id("com.google.gms.google-services") version "4.4.2" apply false
}
Remember to update the Kotlin version to 2.1.0 in libs.versions.toml to make it compatible with the firebase versions.
Now, sync the project to download the dependencies.
Navigate to app > manifests > AndroidManifest.xml and add the following permission.
<uses-permission android:name="android.permission.INTERNET"/>Navigate to MainActivity.kt and activity_main.xml and add the following codes.
Copy SHA1 and SHA-256 keys from your project and paste them to the firebase console. Below is the screenshot to guide you.
👁 ImageNote: Please refer to this article How to Generate SHA1, MD5, and SHA-256 Keys in Android Studio?
On the Firebase console go to Project Overview > Project Setting, and click add fingerprint button, and add your SHA keys copied from firebase
In the Firebase console choose your project, open the Authentication section. On the Sign-in Method page, enable the Phone Number sign-in method.
👁 Image