You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Android Util Library Contain a Small Collection of libraries that we commonly use in our android projects. In the current version, it contains OtpView with SmsRetriver Api and Phone number util with phone number Picker and also Parse a phone number with phone code.
Android Util Library Contain a Small size Collection of libraries that we commonly use in our android projects. In the current version, it contains OtpView with SmsRetriver Api and Phone number util with phone number Picker and also Parse a phone number with phone code.
What's New in Ver 1.0
Phone number Util
Parse a phone number with a phone code.
Phone Picker with Country flag and phone Code.
Otp View
OTP custom view Tag with different features.
Auto Read Sms by using SMS Retriever API.
Sample Images:
Prerequisites
Android 17
Installing
Step 1:- Add it in your root build.gradle at the end of repositories:
Get a callback when the user starts to enter and complete the OTP
OtpView.setOtpListener(new OTPListener() { @Override public void onUserInteraction() { // start when user types something in the Otpbox } @Override public void onOTPComplete(String otp) { // start when user has entered the OTP fully. Toast.makeText(MainActivity.this, "The OTP is " + otp, Toast.LENGTH_SHORT).show(); } });
Some Additional Methods
OtpView.setOTP(otpString); // sets the entered otpString OtpView.getOTP(); // retrieves the OTP entered by user OtpView.showSuccess(); // shows the success state to the user OtpView.showError(); // shows the Error state to the user OtpView.resetState();
OtpView Attributes
Attribute
Description
android:textColor
set text color ot otp
app:length
set lenght of the otp
app:hide_otp
set whether shoe=w or hide the otp
app:hide_otp_drawable
set your own custom hide otp drawable
app:height
set height of each box
app:width
set width of each box
app:bar_enabled
below bar in each otp bpx enable or not
app:bar_height
set height of below bar
app:bar_margin
sets the space between each box in otp view
app:bar_active_color
bar active color when otp is entered
app:bar_inactive_color
bar inactive color when otp is already entered
app:bar_error_color
show wrong otp error by set bar error color
app:bar_success_color
show success otp by set bar success color
app:otp_box_background
set background of otp box
Add the below code to enable Auto Sms Retriever or Autofill OTP code
Add Broadcast in Activity to receive data and message
override fun onResume() { LocalBroadcastManager.getInstance(this).registerReceiver(sms BroadcastReceiver, IntentFilter(MySmsRetriever.SMSLOCALBROADCASTE)) super.onResume() }
override fun onPause() { LocalBroadcastManager.getInstance(this).unregisterReceiver(smsBroadcastReceiver) super.onPause() }
private val smsBroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { if (intent?.action.equals(MySmsRetriever.SMSLOCALBROADCASTE)){ val data = intent?.getBundleExtra("extra") -- > this giev you all data or code related to sms val mess = intent?.getStringExtra(MySmsRetriever.SMS_DATA) -> if only want only messsage from sms then use this only otpView?.setOTP(mess?.getOtpCode(6)!!) } } }
Otp code retriever Helper
use below one if your mess contains integer code with x digit else you can make your logic to extract it.
Sample SMS
Your OTP Code is: 123456
FA+9qCX9VSu --> SMS Signature
mess?.getOtpCode(no fo int code in mess )!!
How to get SMS Signature and why we need this?
First , read this blog to understand in detail Click Here
To get Sms Signature use the below code
val sig = AutoReadSmsUtil.getSmsAppSignature(WeakReference(this))
How to Use FlagView Util
Add the following to your XML design to show the FlagView
// in kotlin flag_view.getFormatNumber("+910123456789")?.apply { code.text = "Phone Code is " + phoneCode phone_number.text = "Phone Number is " + formattedNumber editTextTextPersonNumber.setText(formattedNumber) }
// in java
ParsedNumberData c = flag_view.getFormatNumber("+910123456789")
What ParsedNumberData Contains
coutryCode -> it gives you country code of that phone number phoneCode -> it gives you phone code with + if you number contain formattedNumber -> parse mobile number phoneNumberCode -> only phone code without + countryName -> country name of that phone number int loadFlagByCode(Context c) -> give you flat int id just call it.
How to Open country code Picker?
// but make sure first enable Country picker like in XML or code
app:enableCountryPicker = "true" --> in xml flag_view.enableCountryCodePicker(true) --> in code
flag_view.setCountryPickerListener(CountryPicker.OnCountryPi ckerListener { country -> Toast.makeText(this,country.phoneCode +","+country.countryName,Toast.LENGTH_SHORT).show() })
Bugs, Feature requests
Found a bug? Something that's missing? Feedback is an important part of improving the project, so, please
open an issue
License
Copyright (c) delight.im
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable la w or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
About
Android Util Library Contain a Small Collection of libraries that we commonly use in our android projects. In the current version, it contains OtpView with SmsRetriver Api and Phone number util with phone number Picker and also Parse a phone number with phone code.