0

I am developing an application that I need to find user phone number. I founded Telephony Manager but this class does not guarantee that the phone number always returns.so i want to know is there any solution(probably not a straight solution that can i give users phone number because the number does not coded on sim card) in android?

CoderInNetwork
  • 2,923
  • 4
  • 22
  • 39
  • What kind of phone? GSM or CDMA? – Otra Nov 07 '12 at 12:38
  • `getLine1Number()` will only return the phone number off the SIM card. Sometimes there is no number on the SIM card and sometimes (in cases where the user has changed his number) it will deliver the wrong number. The only sure way to get it is to ask the user to enter it. – David Wasser Nov 07 '12 at 12:40
  • This question has been asked about a million times on StackOverflow. You should have searched first. – David Wasser Nov 07 '12 at 12:41
  • @DavidWasser i didn't ask for TelephonyManager .I only asked about standard practice that someone used in this situations :) – CoderInNetwork Nov 07 '12 at 12:43
  • Unfortunately the standard practice is to use `TelephonyManager.getLine1Number()` and then complain because it doesn't work :-( – David Wasser Nov 07 '12 at 13:01

2 Answers2

0

You don't have much possibilities here you can use either :

TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();

Which as you said is not guaranteed to always return a number. Or you can ask user to enter the number manually. I think there's no other option.

slezadav
  • 6,104
  • 7
  • 40
  • 61
0

Only few service providers provide phone number via getLine1Number() method. Instead you can get a unique number for each sim using getSimSerialNumber() method.

Ask the user to enter phone number, you can store his simnumber using getSimSerialNumber(); Then authenticate depending on the sim number, this should solve your problem

Anirudh
  • 2,767
  • 5
  • 69
  • 119