开发者

How to fetch own mobile number in android [duplicate]

开发者 https://www.devze.com 2023-02-08 06:53 出处:网络
This question already has answers here: 开发者_高级运维 Programmatically obtain the phone number of the Android phone
This question already has answers here: 开发者_高级运维 Programmatically obtain the phone number of the Android phone (22 answers) Closed 9 years ago.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消