ads_header

How To Create One Time Password Input | Android Studio & Java



Hello guys, this tutorial I will make an OTP Online Time Password input. OTP is a verification code or a one-time password consisting of 6 unique (often numeric) secret characters that are generally sent via SMS or e-mail. Each code sent is generally only valid for 5 minutes.





Okay, first open your Android Studio, then open build.gradle (module.app) then add the following dependencies
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_vertical"
    android:background="#0c0f18"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:text="MASUKKAN KODE VERIFIKASI"
        android:textColor="#ffffff"
        android:textSize="30dp"
        android:textStyle="bold"
        android:layout_marginBottom="30dp"/>

    <in.aabhasjindal.otptextview.OtpTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/otp_view"
        android:textColor="#ffffff"
        app:height="90dp"
        android:layout_gravity="center_horizontal"
        app:width="50dp"
        app:bar_enabled="true"
        app:bar_success_color="#43a047"
        app:bar_active_color="#ffee58"
        app:bar_height="2dp"
        app:length="5"
        app:otp_text_size="50dp"
        />

</LinearLayout>


When it's finished the design will look like this


Next, we open MainActivity.java and enter the following code


import androidx.appcompat.app.AppCompatActivity;
import in.aabhasjindal.otptextview.OTPListener;
import in.aabhasjindal.otptextview.OtpTextView;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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

        otpTextView = findViewById(R.id.otp_view);
        otpTextView.setOtpListener(new OTPListener() {
            @Override
            public void onInteractionListener() {

            }

            @Override
            public void onOTPComplete(String otp) {
                if (otp.equals("12345")){
                    otpTextView.showSuccess();
                    Toast.makeText(MainActivity.this,"Kode Verifikasi Benar "+ otp, Toast.LENGTH_LONG).show();  
                }
                else{
                    otpTextView.showError();
                    Toast.makeText(MainActivity.this,"Kode Verifikasi Salah", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}





In the code above I make a condition if the OTP TextView type the number "12345" then the OTP code is declared correct, and if otherwise it is declared false. After all is done and there are no errors, the program is ready to run.

Source Code : Github



9 comments:

  1. If you're looking for help in using it, just dial Quickbooks Customer Service +1 855-675-3194 to speak with a live representative.

    ReplyDelete
  2. Thanks for sharing your blog. In this Blog you have given an Informative Information which are very important for users.

    whmcs integration

    ReplyDelete
  3. Digital marketing and eCommerce services are becoming increasingly important for businesses of all sizes. By joining us, you can boost your business online and take advantage of our eCommerce platform. With zero commission fees, you can sell your products easily and reach a larger audience than ever before. With our digital marketing services, you can also reach new customers and grow your business. Contact us today to learn more about how we can help you boost your business online.

    ReplyDelete
  4. Thanks for sharing your blog. In this Blog you have given Informative Information which is very important for users. What is cPanel cPanel is an online Linux-based graphical user interface (GUI) that serves as a control panel for website and server administration. You can use cPanel to publish websites, manage domains, organize web files, create email accounts, and do other things.

    ReplyDelete
  5. Duelbits Promo Code in 2022
    Get Duelbits Referral Code Now! Just register with Duelbits Promo Code “freecoupon” and claim your Duelbits Bonus today! https://casinoonline-bet.com/duelbits-promo-code/

    ReplyDelete
  6. Glownosity Skin Bar is the Best Skincare Brand. All the services provide in skincare such as soaps, Lip Scrubs, Body butter, Body Scrubs, Bathroom Essentials, Face Masks, Sage, Home fragrances & Body Oil. Skincare Services Waxing And Handmade Skin Care Products are in Las Vegas, NV in United State. Glownosity is a symbol of loyalty and trust. Get the best Skincare Services and detailed information please visit our website https://glownosity.us/

    ReplyDelete
  7. Hello there! I just want to offer you a big thumbs up for your great info you have right here on this post. I'll be coming back to your web site for more soon.
    https://www.webranksindia.com/

    ReplyDelete
  8. QuickBooks to get help with the software or to get help with other important financing needs. You can also contact them for help with your business credit cards. QuickBooks is a business accounting software for small businesses. It helps you keep track of your finances and plan for the future. This software is easy to use, affordable, and has a large user base. For help with QuickBooks or other important financing needs contact them at QuickBooks Customer Service

    ReplyDelete

Powered by Blogger.