0

i want to take the phone number from the phone dialer to use it in my application for that i used this code in the manifest file

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

         <intent-filter >

         <action android:name="android.intent.action.CALL" />

         <action android:name="android.intent.action.CALL_PRIVILEGED" />

          <category android:name="android.intent.category.DEFAULT" />
           <data android:scheme="tel" />

enter image description here

and to get the phone number that i call , so i did use this method

 TelephonyManager phoneManager = (TelephonyManager) 
              getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
        String phoneNumber = phoneManager.getLine1Number();

but its return null when no sim card and nothing when its included

so is there any other method to get the phone number that i use into my application

steevoo
  • 621
  • 6
  • 18

1 Answers1

1

some times you may be unable to get phone number since it is not burned on the sim card , but instead it's saved on the service provider you are using . it's like the DNS server . but for sim cards. so you are unable to read that phone number .....

if you want to get the outgoing calls number make a broad cast receiver see this tutorial it will make the work

confucius
  • 13,127
  • 10
  • 47
  • 66
  • its return nothing and i don't read any phone number when the sim card is included !!!!! – steevoo Jan 17 '12 at 08:36
  • if you want to read the phone number of device by " your method " the number should be burned into the sim card it self , sometime the number is not burned to the sim card so you will get nothing in this case , if you want to do it like this make a message loop . send a sms to you the device it self . – confucius Jan 17 '12 at 08:41
  • but how skype or viber can retrieve the phone number without any simcard included in the phone, should there be a method can do it !!! – steevoo Jan 17 '12 at 09:37
  • okay i did it once , i let the user enter their mobile number then i send an sms to the number they entered which is get catched by a broad cast receiver that get the incoming sms , when the message arrive i check if it has the special body i send , and this way i have their mobile phone , another way is to send their mobile phone number to your server and your server send an sms with an activation code and return the same activation code to your app then when the server sms received on your mobile enter the activation code in you application and it must match the one sent by server . – confucius Jan 17 '12 at 09:53
  • its so complicated and should be there something simplest than what u tell !! – steevoo Jan 17 '12 at 10:21
  • really?? please tell me if you found something simplest than my approaches , i am interested about this topic :) good luck – confucius Jan 17 '12 at 10:34