Programmatically obtain the phone number of the Android phone -


how can programmatically phone number of device running android app?

code:

telephonymanager tmgr = (telephonymanager)mappcontext.getsystemservice(context.telephony_service); string mphonenumber = tmgr.getline1number(); 

required permission:

<uses-permission android:name="android.permission.read_phone_state"/>  

caveats:

according highly upvoted comments, there few caveats aware of. can return null or "" or "???????", , can return stale phone number no longer valid. if want uniquely identifies device, should use getdeviceid() instead.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -