Skip to content

add telecom api #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ SendOTP Android Sdk!

The **SendOtp** Verification SDK makes verifying phone numbers easy. SDK supports the verification of phone numbers via **SMS & Calls**.




----------

Getting started
Expand All @@ -22,7 +25,7 @@ Just add below dependency in project's app level build.gradle file

dependencies {
...
implementation 'com.msg91.sendotpandroid.library:library:1.3.8'
implementation com.msg91.sendotpandroid.library:library:1.4’
...
}

Expand All @@ -33,7 +36,7 @@ Also, add below url in project's project level build.gradle file
url "https://dl.bintray.com/walkover/Android-Libs"
}


**New Update**: Auto verify if same mobile number sim is insrted in device.

Maven
------
Expand Down Expand Up @@ -70,7 +73,7 @@ After login at [MSG91](https://control.msg91.com/) </i> follow below steps to ge

> initialize'**SendOTP**' in your Application class.

public class ApplicationClass extends Application {
public class AppController extends Application {
@Override
public void onCreate() {
super.onCreate();
Expand Down Expand Up @@ -131,14 +134,6 @@ manually **verifying OTP**

SendOTP.getInstance().getTrigger().resend(RetryType.TEXT);

**onDestroy**

@Override
protected void onDestroy() {
super.onDestroy();
SendOTP.getInstance().getTrigger().stop();
}



**customize message text** :
Expand Down
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation "com.msg91.sendotpandroid.library:library:1.4" // added sednotp sdk dependecy


testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.msg91.sendotpandroid.library:library:1.3.8'
}
13 changes: 10 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
package="com.msg91.sendotp.sample">


<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
android:name=".ApplicationClass"
android:name=".AppController"
android:allowBackup="true"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyMaterialTheme"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:name=".ui.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
Expand All @@ -22,7 +29,7 @@
</intent-filter>
</activity>
<activity
android:name=".VerificationActivity"
android:name=".ui.VerificationActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />

Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/com/msg91/sendotp/sample/AppController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.msg91.sendotp.sample;

import android.app.Application;

import com.msg91.sendotpandroid.library.internal.SendOTP;


/**
* Copyright (C) sendotp-android - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* <p>
* Created by Samset on 23,October,2020 at 6:34 PM for sendotp-android.
* <p>
* New Delhi,India
*/


public class AppController extends Application {
@Override
public void onCreate() {
super.onCreate();
SendOTP.initializeApp(this,"authKey");

}
}
13 changes: 0 additions & 13 deletions app/src/main/java/com/msg91/sendotp/sample/ApplicationClass.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.msg91.sendotp.sample;
package com.msg91.sendotp.sample.core;

import android.app.Dialog;
import android.content.Context;
Expand All @@ -8,6 +8,18 @@
import android.view.WindowManager;
import android.widget.TextView;

import com.msg91.sendotp.sample.R;

/**
* Copyright (C) sendotp-android - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* <p>
* Created by Samset on 23,October,2020 at 6:34 PM for sendotp-android.
* <p>
* New Delhi,India
*/

public class DataManager {
private static final DataManager ourInstance = new DataManager();
private boolean isProgressDialogRunning;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
package com.msg91.sendotp.sample;
package com.msg91.sendotp.sample.ui;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import com.msg91.sendotp.sample.R;
import com.msg91.sendotp.sample.utils.CountrySpinner;
import com.msg91.sendotp.sample.utils.NetworkUtils;
import com.msg91.sendotpandroid.library.internal.Iso2Phone;
import com.msg91.sendotpandroid.library.utils.PhoneNumberFormattingTextWatcher;
import com.msg91.sendotpandroid.library.utils.PhoneNumberUtils;

import java.lang.reflect.Method;
import java.util.Locale;


public class MainActivity extends AppCompatActivity {

public static final String INTENT_PHONENUMBER = "phonenumber";
Expand All @@ -32,15 +41,15 @@ public class MainActivity extends AppCompatActivity {
private TextView mSmsButton;
private String mCountryIso;
private TextWatcher mNumberTextWatcher;
private NetworkUtils networkConnectivity;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main_new);
mPhoneNumber = findViewById(R.id.phoneNumber);
mSmsButton = findViewById(R.id.smsVerificationButton);

networkConnectivity = NetworkUtils.getInstance();
mCountryIso = PhoneNumberUtils.getDefaultCountryIso(this);
final String defaultCountryName = new Locale("", mCountryIso).getDisplayName();
final CountrySpinner spinner = (CountrySpinner) findViewById(R.id.spinner);
Expand All @@ -59,6 +68,7 @@ public void onCountryIsoSelected(String selectedIso) {
resetNumberTextWatcher(mCountryIso);

tryAndPrefillPhoneNumber();

}

private void tryAndPrefillPhoneNumber() {
Expand All @@ -75,8 +85,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
tryAndPrefillPhoneNumber();
} else {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0])) {
Toast.makeText(this, "This application needs permission to read your phone number to automatically "
+ "pre-fill it", Toast.LENGTH_LONG).show();
Toast.makeText(this, "This application needs permission to read your phone number to automatically pre-fill it", Toast.LENGTH_LONG).show();
}
}
}
Expand All @@ -93,7 +102,12 @@ private void setButtonsEnabled(boolean enabled) {
}

public void onButtonClicked(View view) {
openActivity(getE164Number());
if (networkConnectivity.isNetworkAvailable(this)) {
openActivity(getE164Number());
} else {
Toast.makeText(this, "Internet not availble ", Toast.LENGTH_SHORT).show();
}

}

private void resetNumberTextWatcher(String countryIso) {
Expand Down Expand Up @@ -137,4 +151,6 @@ private String getE164Number() {
return mPhoneNumber.getText().toString().replaceAll("\\D", "").trim();
// return PhoneNumberUtils.formatNumberToE164(mPhoneNumber.getText().toString(), mCountryIso);
}


}
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
package com.msg91.sendotp.sample;
package com.msg91.sendotp.sample.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.msg91.sendotp.sample.R;
import com.msg91.sendotp.sample.core.DataManager;
import com.msg91.sendotp.sample.utils.NetworkUtils;
import com.msg91.sendotp.sample.utils.OtpEditText;
import com.msg91.sendotpandroid.library.internal.SendOTP;
import com.msg91.sendotpandroid.library.listners.VerificationListener;
import com.msg91.sendotpandroid.library.roots.RetryType;
import com.msg91.sendotpandroid.library.roots.SendOTPConfigBuilder;
import com.msg91.sendotpandroid.library.roots.SendOTPResponseCode;


public class VerificationActivity extends AppCompatActivity implements
ActivityCompat.OnRequestPermissionsResultCallback, VerificationListener {
private static final String TAG = "VerificationActivity";
private static final int OTP_LNGTH = 4;
TextView resend_timer;
private OtpEditText mOtpEditText;
private NetworkUtils networkConnectivity;


@Override
protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verification);
resend_timer = (TextView) findViewById(R.id.resend_timer);
Expand All @@ -46,8 +50,15 @@ public void onClick(View v) {
startTimer();
mOtpEditText = findViewById(R.id.inputCode);
mOtpEditText.setMaxLength(OTP_LNGTH);
enableInputField(true);
initiateVerification();
networkConnectivity = NetworkUtils.getInstance();
if (networkConnectivity.isNetworkAvailable(this)) {
enableInputField(true);
initiateVerification();
} else {
Toast.makeText(this, "Internet not availble ", Toast.LENGTH_SHORT).show();
}


}

void createVerification(String phoneNumber, int countryCode) {
Expand All @@ -65,7 +76,6 @@ void createVerification(String phoneNumber, int countryCode) {
.setMessage("##OTP## is Your verification digits.")
.setOtpLength(OTP_LNGTH)
.setVerificationCallBack(this).build();

SendOTP.getInstance().getTrigger().initiate();


Expand All @@ -91,14 +101,18 @@ public void ResendCode() {

public void onSubmitClicked(View view) {
String code = mOtpEditText.getText().toString();
if (!code.isEmpty()) {
hideKeypad();
verifyOtp(code);
DataManager.getInstance().showProgressMessage(this, "");
TextView messageText = (TextView) findViewById(R.id.textView);
messageText.setText("Verification in progress");
enableInputField(false);

if (networkConnectivity.isNetworkAvailable(this)) {
if (!code.isEmpty()) {
hideKeypad();
verifyOtp(code);
DataManager.getInstance().showProgressMessage(this, "");
TextView messageText = (TextView) findViewById(R.id.textView);
messageText.setText("Verification in progress");
enableInputField(false);
}
}else {
Toast.makeText(this, "Internet not availble ", Toast.LENGTH_SHORT).show();
}

}
Expand Down Expand Up @@ -160,7 +174,7 @@ public void onSendOtpResponse(final SendOTPResponseCode responseCode, final Stri
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e(TAG, "onSendOtpResponse: " + responseCode.getCode() + "=======" + message);
//Log.e(TAG, "onSendOtpResponse: " + responseCode.getCode() + "=======" + message);
if (responseCode == SendOTPResponseCode.DIRECT_VERIFICATION_SUCCESSFUL_FOR_NUMBER || responseCode == SendOTPResponseCode.OTP_VERIFIED) {
DataManager.getInstance().hideProgressMessage();
enableInputField(false);
Expand Down Expand Up @@ -194,12 +208,14 @@ public void run() {
DataManager.getInstance().hideProgressMessage();
} else if (responseCode == SendOTPResponseCode.NO_INTERNET_CONNECTED) {
DataManager.getInstance().hideProgressMessage();
Toast.makeText(VerificationActivity.this, "Internet not availble ", Toast.LENGTH_SHORT).show();
} else {
DataManager.getInstance().hideProgressMessage();
hideKeypad();
hideProgressBarAndShowMessage(R.string.failed);
enableInputField(true);
}
SendOTP.getInstance().getTrigger().stop();
}
});
}
Expand Down Expand Up @@ -233,9 +249,5 @@ private void hideKeypad() {
}
}

@Override
protected void onDestroy() {
super.onDestroy();
SendOTP.getInstance().getTrigger().stop();
}

}
Loading