This question already has an answer here:
Get MSISDN from the SIM using Android
(1 answer)
Closed 9 years ago.
Can I access the mobile number of a device after installing an app? I can ask from the user for it but need to ensure that it is the correct number that he is inputting. Is there a way? Just need a way to ensure that the app is downloaded on the same mobile number device.
Some SIM providers save the number on the SIM. You can directly extract from SIM without user interaction. Use TelephonyManager as follows:
TelephonyManager teleManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String getSimNumber = teleManager.getLine1Number();
Although, it turns out that there might be a case when SIM is present and still you cannot read the number. Some SIM cards doesn't allow to do so while others just don't have the number in the SIM(since this field is not mandatory). Quoting TelephonyManager.getLine1Number() failing?, Android issue about TelephoneManager and this blog, you'll get to know that the presence of number within the SIM isn’t required for operation and is actually assigned directly by the network itself.
Hope this helps.
Related
This question already has answers here:
Getting telephone US local area code with Android
(10 answers)
Closed 5 years ago.
I want to get user's country from the sim card and it should not be changed if he is in roaming i.e. If I have sim card of India and I am travelling to US then still I should get the country as India only not US.
So what should I use - getNetworkCountryIso() or getSimCountryIso().
I am really confused between two since I have read somewhere that getNetworkCountryIso() returns current country, that means it will be changed if I am in international roaming.
getSimCountryIso
getSimCountryIso depends on the operator to burn the country iso on the SIM and it also supports CDMA networks
getNetworkCountryIso()
Returns the ISO country code equivalent of the current registered operator's MCC (Mobile Country Code).
for more information read TelephonyManager
This question already has answers here:
MSISDN : Is it a SIM Card Data? Why all The Provided Function (from Blackberry and Android) to fetch MSISDN not reliable?
(3 answers)
Closed 5 years ago.
I want to get the mobile number of users, which will be defaultly taken as username, when I used the following code to get the mobile number, it returns an empty string
TelephonyManager tMgr = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
mPhoneNumber = tMgr.getLine1Number();
String mobNo = mPhoneNumber.replace("+", "");
One reason I found is My phone number is unknown under Settings->About Phone->Status->SIM Status. How to rectify this issue without giving any burden to the users.
There are at least some SIM Cards/Operators out there who don't provide numbers - I have seen it and you have seen it. There is probably nothing you can do about it.
See getLine1Number() documentation. It says if its unavailable, it returns null. So #sstn is partially right. You can't do much about it. As far as I can remember this method gets number which is stored in the SIM. Some providers restrict the access and other don't provide it.
However that being said if you are really really pushing to get phone number from network automatically, you can try one more thing. Most of the network providers provide their own API. The API might require the user to connect to internet through the network data and not wi-fi or any other method. Although different providers in different countries can differ on that. You can potentially recognize the network provider using getNetworkOperator(), then use provider specific API to get the number. However not sure if its free. For eg: In Canada, Telus has its API but it requires you to partner with them. Similarly with Rogers etc.
If you don't want to go through that pain, the last option is to ask the user to enter it. If you are worried about its validity then you can always do one time code SMS verification.
Hope it helps.
This question already has answers here:
MSISDN : Is it a SIM Card Data? Why all The Provided Function (from Blackberry and Android) to fetch MSISDN not reliable?
(3 answers)
Closed 5 years ago.
Without asking the users to input their mobile numbers, I want to get the current mobile phone number associated with that mobile, so that I can send particular messages about deals and offers available at a particular location or country, by getting the mobile phone number when my app is installed at the first time. Is it possible in android? Will there be any problems associated with it, if I'm able to collect mobile phone numbers of users? I would like to more deepely about it. So comments and answers to my question are extremely welcomed. Since I don't know where to start with, any tutorials or related links are also welcomed..
TelephonyManager mManager =(TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = mManager.getLine1Number();
// check if mPhoneNumber is null then there is no number saved in the phone.
and set in manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
and further reading here
hope it helps :)
Spurdow's answer is correct but works only if the number is available in the system. Not all the countries and/or wireless carriers support that. I tested reading phone number, and it gave my T-mobile phone number in USA correctly, whereas returned no number in a friend`s phone in Turkey. So plan your code accordingly(i.e., check a possible null result, ask the phone number to user etc.). For more information:
https://developer.android.com/reference/android/telephony/TelephonyManager.html#getLine1Number%28%29
Following scenario:
I want to create an wifi hotspot on a public place (e.g. train station). Therefore i want to write an mobile application (iOS and/or Android) which works as a portal page. As I would be providing internet access via my wifi hotspot I need to make sure that people who want to log in verify their identity properly (responsibility). First I thought i could do something like a facebook login but I guess that would not be enough as people can create fake accounts.
Then I got the idea that I could maybe access their telephone number via their smartphones.
I googled alot and came to the conclusion that it is pretty tough on both platforms.
The iOS method seems to be deprecated and apps wont make it to the app store with that version. Android can read the phone number from the sim card, but not all providers store the number on the sim card.
Question
Is there any possibility to get the phone number? Or is there any other way to uniquely identify a person in a wifi network?
Of course I dont want to do any of that without asking for users permission etc...
Greetings and thanks in advance
Peter
Choosing the MAC address is a good choice, it is not the safest, but it is the more easy to do.
The IMEI is not always provided, and the SERIAL is not uniq.
But actually, I don't know how to do this with iOS.
What is about the MAC address of the phone? This should be unique enough and you can get is easily from android and from iOS.
Android: http://developer.android.com/reference/android/net/wifi/WifiInfo.html#getMacAddress%28%29
iOS: How can I programmatically get the MAC address of an iphone
Using IMEI number
Android Does provide functions/method to access device IMEI number
First Set <uses-permission android:name="android.permission.READ_PHONE_STATE" />
in android manifest
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
Hope it helps
For NON CDMA or GSM devices like Tablet
Use
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
This would generate a unique code for the device..how ever it would change on when user reset the device ie factory reset it .. and it works for device having os > 2.2(froyo)
This really depends on who you are trying to identify. That may seem like an odd response, but usually, we are trying to identify two, not one, sets of credential elements.
First, we want ot identify the device itself -- is this the deivce we expect to see and can we trust that this device has not been tampered with. Second, we usually want to know if the user of this device at the moment is one we expect to be using this, now validated, device. (If I take your phone, without step #2, I just became you.)
This is why we have things like 802.1x. It lets me validate the user of a network, not just the device. For your case, consider something like:
For device validation, the combination of hte MAC address and the IMEI. TUrn those into a unique hash with some data from the user. For example.
ID = SHA1(IMEI+MAC(Wifi)+user password)
Now that we're pretty sure the device and user are correct, if you need to, you can go one step further and use that hash a key to encrypt a user validation step in your app. Even if the user is correct, if they're on the wrong device, their key won't decrypt.
I want to create an application where the application will ask user to register with user details while using the app for the first time. This information will be stored in a remote database. Next time when user opens the application I want to identify the user from my database.
Now to implement this, I will have to find a unique identifier for each phone.
Could anyone let me know how to get unique identifier for each phone.
Regards,
Shannkar
You should read this: http://android-developers.blogspot.com/2011/03/identifying-app-installations.html
The problem with using the phone number is phone numbers change, get recycled, etc. SIM cards change. Get swapped. Etc. I've had real production experience with this.
I've had good results having users enter their serial# or ESN.
Or use the IMEI. You should be able to access it via the API.
If you want it automated, and cannot access the ESN or IMEI, then generate a GUID and store it on persistent storage in the device.
You can use IMEI as the unique identification.you can get IMEI of android device in the following way
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();
check my similar question here to get IMEI (UUID) number
How can I get the UUID of my Android phone in an application?