I have done the sim/mobile number verification (same like Whats APP) part in my app. something like:
Send Message Part:
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(mobileNumber, null, "Welcome", null, null);
Check the message received by the same/current device through BroadcastReceiver:
private class SMSReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction() != null && intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle extras = intent.getExtras();
if (extras == null){
_submit.setText("Register");
_mobile_number.setError("Invalid Number");
mProgressDialog.dismiss();
return;
}
try{
Object[] pdus = (Object[]) extras.get("pdus");
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[0]);
String origNumber = msg.getOriginatingAddress();
String msgBody = msg.getMessageBody();
String countryCode = country_codeselected ;
String number = _mobile_number.getText().toString();
final String mobileNumber = countryCode+number;
final String reg_id = prefs.getString(GCM_REG_ID, "");
if(PHONE_NUMBER.equals(origNumber)){
//Success
}
.............................
Its working only for Single SIM devices.
Can anyone help me that how to do this for dual SIM devices.
Suggestions are mostly appreciable.
i think
https://github.com/cognalys/cogdemo will be helpful
Because its a new way of verifying mobile number without fee . SMS method is a traditional method.
private void isDualSimOrNot(){
SimNoInfo telephonyInfo = SimNoInfo.getInstance(this);
String imeiSIM1 = telephonyInfo.getImeiSIM1();
String imeiSIM2 = telephonyInfo.getImeiSIM2();
boolean isSIM1Ready = telephonyInfo.isSIM1Ready();
boolean isSIM2Ready = telephonyInfo.isSIM2Ready();
boolean isDualSIM = telephonyInfo.isDualSIM();
Log.i("Dual = "," IME1 : " + imeiSIM1 + "\n" +
" IME2 : " + imeiSIM2 + "\n" +
" IS DUAL SIM : " + isDualSIM + "\n" +
" IS SIM1 READY : " + isSIM1Ready + "\n" +
" IS SIM2 READY : " + isSIM2Ready + "\n");
}
For further implementation go through this link Android How to get Phone number from the Dual sim phone
I would avoid doing it that way since it only works on Android. Plus, what number will you be sending it to? If you send it from the SIM card, then what will you do when the SIM does not return any data? - and If you send it to the phone number that the user entered, when they find out it came out of their own phone, you will need to add a big disclaimer about SMS charges they might incur.
You can alternatively use RingCaptcha - a new service that helps you onboard verified users into your apps in seconds via SMS. Integration is a breeze with all the available plugins for web, APIs, and SDKs of all flavours.
[Disclaimer: I'm part of the team behind RingCaptcha]
来源:https://stackoverflow.com/questions/27437699/mobile-number-verification-for-dual-sim-devices-in-android