1

I am trying to get the user's phone number but the problem is that I am getting null response based on my research so far we can get the same by using the object of TelePhony Manager and calling function getLine1Number()

but I am not getting any response,somebody suggested that this is because the service provider is not providing the same in my country I am in India but for blackberry it's providing the phone number so what could be the possible problem please suggest my whole algo depends on this.

Aashish Bhatnagar
  • 2,595
  • 2
  • 22
  • 37
  • 1
    have you check ? http://stackoverflow.com/questions/1853220/retrieve-incoming-calls-phone-number-in-android – Nikhil Jul 25 '12 at 10:43
  • what do you mean when you say, for blackberry its providing? – Aswin Kumar Jul 25 '12 at 10:44
  • 1
    check my erlier answer http://stackoverflow.com/questions/11534534/android-reading-device-phone-number-throws-nullpointerexception/11534625#11534625 – jeet Jul 25 '12 at 10:45
  • Thanks jeet your answer is really helpful you mean to say it's unavailable in India but I can get that for the Brazilian users ? – Aashish Bhatnagar Jul 25 '12 at 10:51

3 Answers3

1

Have you added the permission

<uses-permission android:name="android.permission.READ_PHONE_STATE">
</uses-permission>

to your AndroidManifest.xml file?

biddulph.r
  • 5,226
  • 3
  • 32
  • 47
  • I am using this I am trying to obtain user's own phone number – Aashish Bhatnagar Jul 25 '12 at 10:45
  • Retrieving the device's associated phone number isn't an exact art - some sim cards do not readily provide it how Android wants it, so you may be having issues obtaining it because of this – biddulph.r Jul 25 '12 at 10:54
0

have you tried using

String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

If you have already used this, I will recommend that you elaborate your question in a more specific way.

monish_sc
  • 146
  • 6
0

Add this permission to your android manifest file

<uses-permission android:name="android.permission.READ_PHONE_STATE">
</uses-permission>

use following code to get number

number = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);