njnjnj njnjnj - 1 month ago 18
Android Question

Get current mobile phone number of a user in my android application

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

Answer
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 :)

Comments