Reputation: 1
I want to display my phone number on the Android phone. I am using the following code for displaying the number on the phone, but I am getting a null value on the phone. Here is my code:
TelephonyManager tm=(TelephonyManager) mGap.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String imeiId=tm.getLine1Number();
I displayed imeiId
on Device but it is displaying null. Is there any alternative for this problem?
I have added the below code in android manifest .xml
file:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
But it's showing null on the device. I am new to Android PhoneGap applications, so what am I doing wrong?
Upvotes: 0
Views: 1837
Reputation: 4440
Try this actually
private String getMyPhoneNumber(){
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}
private String getMy10DigitPhoneNumber(){
String s = getMyPhoneNumber();
return s.substring(2);
}
Taken from
http://www.androidsnippets.com/get-my-phone-number
Upvotes: 3