How can I build android application be able to access to the user's phone number when you download this application then i retrieve this number ?
For Example:
public class Phonenumber
{
//functions
}
How can I build android application be able to access to the user's phone number when you download this application then i retrieve this number ?
For Example:
public class Phonenumber
{
//functions
}
It is very simple to get user phone number .
TelephonyManager tMgr =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
Required
permission READ_PHONE_STATE in android manifest file.
TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
Requires permission READ_PHONE_STATE
.
Add below part in android manifest xml file.
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
you can use TelePhonyManager.getLineNumber() as other suggested. But I should add one thing. That this is not gurranteed for every operator to get the telephone number by this method. because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. So in some network it may not return the number. So to me the best solution is to ask user to enter telephone number if you want to make your application global.
Moreover it is a duplicate question. See here https://stackoverflow.com/a/6797278/931982.