The SendOtp Verification SDK makes verifying phone numbers easy. SDK supports the verification of phone numbers via SMS & Calls.
Just add the "compile 'com.msg91.sendotp.library:library:3.1'" in your build.gradle of your module.
dependencies {
...
compile 'com.msg91.sendotp.library:library:3.1'
...
}
grab via Maven:
<dependency>
<groupId>com.msg91.sendotp.library</groupId>
<artifactId>library</artifactId>
<version>3.1</version>
<type>pom</type>
</dependency>
-Login or create account at MSG91 to use sendOTP services.
After login at MSG91 follow below steps to get your authkey
- Select API option available on panel.
- If you are first time user then generate new authkey.
- copy authKey & keep it enable, Paste in manifest under application tag.
<meta-data android:name="sendotp.key" android:value="@string/sendotp_key" />
implement 'VerificationListener' in your class & override below result callbacks.
@Override
public void onInitiated(String response) {
Log.d(TAG, "Initialized!" + response);
//OTP successfully resent/sent.
}
@Override
public void onInitiationFailed(Exception exception) {
Log.e(TAG, "Verification initialization failed: " + exception.getMessage());
//sending otp failed.
}
@Override
public void onVerified(String response) {
Log.d(TAG, "Verified!\n" + response);
//OTP verified successfully.
}
@Override
public void onVerificationFailed(Exception exception) {
Log.e(TAG, "Verification failed: " + exception.getMessage());
//OTP verification failed.
}
create instance of Verification as a class variable and initialise
it by passing country code and mobile number.
mVerification = SendOtpVerification.createSmsVerification
(SendOtpVerification
.config("country_code" + phoneNumber)
.context(this)
.autoVerification(true)
.build(), this);
Note : Add SMS read permission for autoVerification.
sending OTP
mVerification.initiate();
manually verifying OTP
mVerification.verify(otp_code);
resend OTP use 'voice' or 'text' as a param.
mVerification.resend("voice");
- message("##OTP## with your Custom OTP message.") [for custom OTP message]
- httpsConnection(false) [connection to be use in network calls]
- expiry(5) [value in minutes]
- senderId("OTPSMS")
- otp("1234") [use your OTP code]
- otplength("4") [custom OTP length]
Copyright 2017 MSG91
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 law 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.