how to obtain mobile number of own device in android? - 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.

Related

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.

The phone return empty when I want to get the phone number

Some phones return null when I want to get the phone number. In other phones I get the phone number.
This happens when Settings -> About Phone -> Status -> My phone number is "Unkow". Not writed there the phone number.
Why is this happening?How can I get a phone number ?
The code:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
And:
TelephonyManager tMgr = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
Your code is perfect to get phone number of Android device.It will return you number.But sometimes it gives you null because that devices Service provider has not given permission to do that.
Means It works like : Android devices Request SIM card/Service provider for card info with phone number. And In response, Some provider have returned phone number of user and some has refused to do so.
Can you clarify what specifically you're asking for? If you're saying that it happens when in your phone's settings, under About Phone->Status->My phone number, it says "Unknown", then unfortunately that's not a programming question and not a question for here. Is that the case?
You cannot get device phone number in any ways. It depends on the service provider, some may allow access and some may not since it is completely dependent on the network access privileges. But in rare case you would get the phone number once the user has configured their own mobile number with the SIM card provider. The other way to do this by fetching the number from Facebook that too the user should have registered their mobile number, whereas the earlier versions of whatsapp provides this feature, but it is not compatible with the newer ones.
Note: It works with few custom phones which provides the access.(i.e., phones synced with only particular network providers)

Retrieving Line1 number from TelephonyManager in Android

TelephonyManager manager1 = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String strMobile1 = manager1.getLine1Number();
This is my code for getting mobile number of but its not working. I have also take necessary permission in manifest file
We had the same problem in our project. The conclusion was that it depends on the SIM card.
What happened to us:
Galaxy S with AT&T SIM card: can read phone number, Settings shows number
Same Galaxy with an European SIM card: cannot read the number and "unknown" in Settings (cell phone was perfectly functional, just couldn't read the number)
This has been reported in other forums as well.
In the end we decided to ask the user for the phone number. A bit more involved, actually: if( "SIM card present" && "cannot read the cell number") "ask user"; . Otherwise we will keep bugging the user that doesn't a SIM card in the first place.
getLine1Number() only get the number stored on the sim card..a lot of operators don't write there the sim number..on some phones (nokia, blackberry, some olds android, iphone) you can set your own mobile number and the phone will store it on the sim card, at that point getLine1Number() will return the phone number
The method you are using is the only one part of the SDK to do this, and only works on devices where the number is stored on the SIM card, which only some carriers do.
For all other carriers, you will have to ask the user to enter the phone number manually, as the number is simply not stored anywhere on the device from where you can retrieve it.
source here

Getting phone number from android mobile phone

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.

How to get mobile numbers if my android phone have two SIM cards?

I have implemented an application for get the SIM cards mobile numbers from my Google Ebony QWERTY touchscreen.In this device i have two SIM cards.I have used TelephonyManager for get mobile number from device as follows
TelephonyManager tMgr = (TelephonyManager) arTnewActivity.getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = tMgr.getLine1Number();
Log.v("Device mobile numbers",getSimSerialNumber);
From the above code it will return a single mobile number but If i run in case of Ebony QWERTY dual sim phone then can i get two sim card serial numbers?
please any body help me..
From what I understand the default SDK does not have support to handle dual sim. From this thread it sounds like you have to ask the manufacturer if they have a special SDK that could provide this.
If it's Google they might have some additional SDK stuffed away somewhere? :-)

Categories

Resources