0

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..

njnjnj
  • 978
  • 4
  • 23
  • 58

2 Answers2

3
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
  • 2,025
  • 18
  • 22
1

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

erol yeniaras
  • 3,701
  • 2
  • 22
  • 40