sim number is not getting in android - android

I used the following code to get to get the sim number and serial number of the sim. But i am getting the sim serial number but not the sim number. I gave the uses permission all the stuffs like that. but i am not getting it.!! Please help me out.!! Thank You.!
TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = telemamanger.getSimSerialNumber();
String getSimNumber = telemamanger.getLine1Number();

SIM number is not compulsory to be there, it's upto the Telecom if they put number inside the SIM card. It's mostly happen they do it for POSTPAID SIM cards, mostly SIMs do not have number so in that case they return null and if it has, it shall return that NUMBER as it is. To make sure your SIM has number or not, do check that in your android mobile settings.
check this link Check SIM number in android

Related

Get all SIM phone numbers

Is it possible to get all SIM numbers (if dual SIM) from phone programmatically? And how?
I know there's a way to check if the phone is dual sim. But I didn't find information how can I exctract actually those numbers.
There's a method to get phone number but it doesn't work for dual sim:
TelephonyManager tMgr = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
String phone = tMgr.getLine1Number();
It is not possible to get phone number with telephonymanager class because some sim manufacturer companies does not provide sim number on sim card as described in this link. https://stackoverflow.com/a/6797278/6448399

how to Obtain mobile number android

I used this code for fetching the number, But it gave me null
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
It may not always return mobile number.
Let me explain how this actually works: When you buy a new SIM card for a new number, the provider had already (though not always) put a mobile number in the SIM (SIM Cards do have a little memory). Now TelephonyManager API tries to read that number. If it is available then it returns the number.
Now, you can get a SIM without a mobile number associated with it. Example - new SIM for porting (where you use previous number in new SIM Card). Those SIMs don't have any number stored on them, and hence TelephonyManager returns null.
Now, even if TelephonyManager returns a number, you should not trust it to be right. Because many devices provide option to edit that number.
To use getLine1Number() you need either READ_PHONE_STATE OR READ_SMS permission. You may be missing that.
And remember that it returns null if phone number string is unavailable.

Getting SIM serial number in Android

I need to make sure the SIM card can be used without entering pin in designated device(s), but it must be required in other devices. (Devices in use are rooted, application is installed as system app)
What I want is to identify a SIM card, and enter the pin programmatically, if one is already known/saved.
I am able to enter the known pin code, when one is required, but I have a problem with SIM identification.
I found out that I am not able to get SIM serial number or subscriber id before the correct PIN is entered.
The method I am using (with permissions and etc.):
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getSimSerialNumber();
The thing is, this method returns null, if pin is required and not yet entered.
My question is if there is some kind of workaround for this.
Is it possible at all?
Is there another approach?
Ideas and approaches appreciated.
Thanks in advance.
TelephonyManager tm = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
}
String simID = tm.getSimSerialNumber();
String telNumber = tm.getLine1Number();
String IMEI = tm.getDeviceId();
Permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Your issue:
The phone number returned is whatever is stored on the SIM card's MSISDN, which is not filled by some operators. Try Airtel, Vodafone if in India.

Get the IMSI number or destination phone number from incomming message (SMS)

I am developing an application that requires the IMSI/phone number of the device(with multiple SIM cards) which receives an sms.
This is basically for identification purpose of which SIM is receiving the sms and later perform further operations.
I have thoroughly searched the SMSMessage Api, but did not find a suitable solution.
Any help would be greatly appreciated.
As I know you can not get the destination phone number, IMSI from the incoming SMS.
You can get the IMSI and phone Number of SIM like this way.
You can get the IMSI number of SIM but I don't think you will be able to get the phone number of all SIM because some manufacture did not save the phone number in SIM so you will get the NULL.
In Android, No way using Android SDK to get the second SIM information. You can get the information of first SIM only.
Android SDK support the first SIM information and Dual SIM features are available from manufacture side hence not officially supported from Android SDK.
Add this AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Add this in where you want to get SIM details.
TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
To get the IMSI of 1st SIM
String imsi = telemamanger.getSimSerialNumber();
To get the Phone Number of 1st SIM
if(telemamanger.getLine1Number() != null)
String phoneNumber = telemamanger.getLine1Number();

Get MSISDN from the SIM using Android

I'm trying to retrieve the MSISDN from the SIM using Android, I have tried getLine1Number() but this only returns the MSISDN stored in My Phone Information or Owner Information secction, if these info is not stored, Android will return a null value.
Do you know any work around from this? or is there a way to derive the MSISDN from the SIM number (getSimSerialNumber())?
Awaits a solid Answer as always !!! :)
The MSISDN (aka the mobile phone number) isn't a SIM data, so you can't retrieve it. The SIM card has an IMSI (International Mobile Subsriber Identity) that is sent to the HLR (Home Location Register) in charge of doing the mapping MSISDN/IMSI.
Mobile phone operators could store the MSISDN on the SIM card if they wanted to, but since it is not required in the GSM protocol it isn't.
Sorry!
For more info look at this discussion Getting phone number also How android get MSISDN
EDIT:
To get IMSI number,
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imsi = mTelephonyMgr.getSubscriberId();
but a few handsets only return 6 digits instead of 15. So, you can use,
According to this post: http://www.anddev.org/tinytut_-_getting_the_imsi_-_imei_sim-device_unique_ids-t446.html
String imei = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
For more info look at This Question and class SystemProperties

Categories

Resources