Getting phone number from android mobile phone - android

Which commands should I use in order to get the sim phone number from an Android mobile phone?
Exploring the sample of phone dialer i found "PhoneDialerService.GetCarrier" but with no option for getting mobile's phone number.

If the device uses only one sim card use :
TelephonyManager phoneManager = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = phoneManager.getLine1Number();
In case the device uses two or more sim cards, use:
TelephonyManager phoneManager = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String simSerialNumber = phoneManager.getSimSerialNumber();
Don't forget the permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Note that there isn't any guaranteed solution. This won't work(might return null) on every device/country because phone numbers are not physically stored on all SIM cards. The best solution is to ask the user to enter his/her phone number once and store it, and ask if number is ported/changed.

Related

Detect two phones/handset with same phone number after phone authentication/OTP

If I use phone A's number to verify an app'X' on phone B. And then install app'X' on phone A and verify the app with its number, Then I have verified two handsets with same mobile number. How can I detect this on the server and restrict such operation ?
This can usually happen when the user owns both the handset/phones.
you can get the IMEI Number of both phones by this code :
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String IMEI = telephonyManager.getDeviceId();
and check that the IMEI Number is differ for both phones because IMEI number is unique for every device.
And you should add the following permission into your Manifest.xml file:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

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();

how to obtain mobile number of own device in android?

I want to retreive mobile number of device programatically. My code is:-
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String strMobileNumber = telephonyManager.getLine1Number();
and I have set READ_PHONE_STATE permission in AndroidManifest.xml file. This is working on emulator but on actual device with eclair version, it is returning empty string. Is there any other way to get mobile no?
There is no reliable way to "retreive mobile number of device programatically", AFAIK. getLine1Number() reports the number supplied by the SIM card for GSM phones, and the mobile number does not need to be on the SIM card.

Categories

Resources