Reputation: 164
I want to verify that user cell number is same as the sim number used in the device during registration in android application.
How do I get the sim number in my app to compare with the user entered number?
If it is impossible then any other verification process?
Upvotes: 3
Views: 8322
Reputation: 112
This code can find the sim number but only if the number is saved our phone directory or we can never find the sim number in any case.
TelephonyManager telephonyManager = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
mobile number = telephonyManager.getLine1Number();
Really it is impossible only those device which has saved their sim number can possible. OTP verification process is best for this , please enter your number and get a otp to verify.
Upvotes: 2
Reputation: 1304
You can find the first sim number using this code.
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mobileNumber = telephonyManager.getLine1Number();
Add this uses-permission
also in manifest.
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
This code will help you but some time it does not return the exact result. Best option is to verify the number after asking the user for their mobile number.
This would help you, it has helped me.
Upvotes: 0
Reputation: 2427
Try following code to get sim serial number and get sim number
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = tManager.getSimSerialNumber();
String getSimNumber = tManager.getLine1Number();
Log.v(TAG, "getSimSerialNumber : " + getSimSerialNumber +" ,getSimNumber : "+ getSimNumber);
Add below permission into your Androidmanifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Upvotes: 0