I want to get mobile number of own mobile.
I searched android telephony class but i can not find any useful function over there.
thanks in advance for your help.
Can do this:
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String yourNumber = mTelephonyMgr.getLine1Number();
Add Permission to Manifest file:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
I think there are cases where the phone does not know its own number - it somehow depends on the network provider / SIM card.
I do have one SIM card where it works, another one (different provider, prepaid) where it does not work.
Try the following code:
TelephonyManager mTelephonyMgr =
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String sDeviceID = mTelephonyMgr.getDeviceId();
String sSimSerial = mTelephonyMgr.getSimSerialNumber();
Set the following permission
android.permission.READ_PHONE_STATE in Android Manifest file
精彩评论