This question already has answers here:
Programmatically obtain the phone number of the Android phone
(22 answers)
Closed 9 years ago.
I want to get mobile number of own mobile, for add this part to my application .
I'm searching about this question ,
code is correct on emulator but in device show empty.
public String getMyPhoneNumber()
{
return ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getLine1Number();
}
and :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
But is it returning empty value. So How can I fetch the phone number detail ?
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.
Answer from: Programmatically obtain the phone number of the Android phone
"There is no guaranteed solution to this problem because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. This is especially true in some countries which requires physical address verification, with number assignment only happening afterwards. Phone number assignment happens on the network - and can be changed without changing the SIM card or device (e.g. this is how porting is supported).
I know it is pain, but most likely the best solution is just to ask the user to enter his/her phone number once and store it."
Your code should be fine, but you need the SIM card to be inserted in the phone. Also, as autocrat noted, if the number is not stored on sim card, you will get an empty string.
EDIT: Also, please check the link provided by Pontus Backlund, there's some good info there.
Go to setting -> about device -> status -> my phone number if my phone number is unknown u won't get mobile number.. because some of the mobile network won't give mobile number..
if my mobile number has number u can get mobile through following code
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
phoneNumber = tManager.getLine1Number();
Related
This question already has answers here:
Programmatically obtain the phone number of the Android phone
(22 answers)
Closed 2 years ago.
In my app i want to show the both inserted sim card mobile number to user in android studio . But i suffer from problem in which , i stuck at getting of second inserted sim mobile number . Help me to solve this.
TelephonyManager - "Provides access to information about the telephony services on the device. Applications can use the methods in this class to determine telephony services and states, as well as to access some types of subscriber information."
Code:
TelephonyManager telephonyManager =(TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
//SIM 1 Number
String mSimPhoneNumber1 = telephonyManager.getLine1Number();
//SIM 2 Number
String mSimPhoneNumber2 = telephonyManager.getLine2Number();
This method might returns a null on some phones.
Required Permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
I am able to retrieve contacts and all of their information, but in the Contact list I do not see "ME". I read that this was not supported, but t there was a ticket to Android about this (back in 2011?).
Is it possible to retrieve MY contact card in Android?
No, because you don't have one unless the user added one. Even if there is one, there's no promise of any actual data on it. Not even phone number, since its possible for a phone to not know its own phone number.
In my app I'm using CallLog's and I'm getting data of calls. I can receive all data, but there is no information about my number phone. How can I receive this information? getLine1Number() from TelephonyManager return empty string..
To get the phone number from the device , first you have to set your own phone number on the device, just through :
Settings -> About Phone -> Status -> My phone Number
Phone numbers are not available on SIM for each operators, like in india Sim dont have phone numbers in any memory, So WE cant get phone number from these connection. However, some countries, and operators have stored phone numbers on SIM, and we can get those.
Yes. This is because not all operators support retrieving phone number from the SIM card. There is no fail-safe way to always retrieve the phone number through your app. Your best bet is to ask the user to enter their phone number into the app and then save it to shared preferences or something.
It depends on Mobile Operator. In India Airtel support this feature.
I obtained the Android serial number by code using
android.os.Build.SERIAL
I then compare it to the serial number found in the Settings menu (Settings-> About device-> Status-> Serial number).
I've tested it, and it seems that on some devices (e.g. Nexus) the two codes are the same, while on others (e.g. Galaxy Note) the two codes are completely different: The Java code returns me a 16-digit alphanumeric (lowercase) code, while on screen I can see an 11-digit alphanumeric (uppercase) code.
How is it possible? Are these two codes the same, or something completely different?
If they are the same, is there a way to convert from one of the two to the other?
Is there a better way to identify the device? I know that I can useĀ
the phone device ID (IMEI, MEID,...), which can be obtained
TelephonyManager tManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
tManager.getDeviceId();
but not all devices are phones, and not all of them have this code;
The Android ID, retrievable by
Secure.getString(context.getContentResolver(),Secure.ANDROID_ID);
But I cannot find it anywhere in the Settings menu, and I need my user to tell me its code by reading it from the user interface.
The app "Android id" on google play(free) shows different ID's like:
android_ID
android.os.build.serial
telephonyManager deviceID
wifi mac
i have a service to get Current Sim Serial and detect whether second sim card is inserted. So i would like to store the first sim card when the service run, Does anyone can tell me which way i can use to store integer value(sim serial).
When the second sim card inserted(after device reboot), i would like to compare the stored sim and current sim, if so detected then do something.
So basically i just want to write a sim card value to storage.
For store integer value(sim serial) You Should Use Android Preferences .
For More Refer these Links
http://developer.android.com/reference/android/preference/package-summary.html
http://viralpatel.net/blogs/android-preferences-activity-example/
http://www.javacodegeeks.com/2011/01/android-quick-preferences-tutorial.html
If you really are in for security id rather suggest using a PaaS like heroku and using your own web application to store that. Anyone can just erase the data from your application and have it think it is its first time running,