How do I get the user's phone number?

7488 views
Skip to first unread message

j

unread,
Aug 19, 2008, 1:30:03 AM8/19/08
to Android Developers
How do I get the user's phone number in 0.9 beta SDK?

Huebi

unread,
Aug 19, 2008, 2:06:21 AM8/19/08
to Android Developers
You need the permission READ_PHONE_STATE, then use
TelephonyManager.getDefault() to get hold of the TelephonyManager. On
the returned instance call mgr.getLine1Number() and there it is :)

Cheers
-Huebi

Jeff Hamilton

unread,
Aug 19, 2008, 1:36:28 AM8/19/08
to android-d...@googlegroups.com

Romain Guy

unread,
Aug 19, 2008, 2:14:47 AM8/19/08
to android-d...@googlegroups.com
Do not use TelephonyManager.getDefault(), this is private API that may
change. Instead use the following:

(TelephonyManager) getSystemService("phone")

--
Romain Guy
www.curious-creature.org

Jeff Hamilton

unread,
Aug 19, 2008, 2:14:52 AM8/19/08
to android-d...@googlegroups.com
You should get the TelephonyManger using
getSystemService(TELEPHONY_SERVICE) instead, like this:

TelephonyManager telephony = (TelephonyManager)
getSystemService(TELEPHONY_SERVICE);

See http://code.google.com/android/reference/android/content/Context.html#TELEPHONY_SERVICE
for the definition of the TELEPHONY_SERVICE constant.

-Jeff

On Mon, Aug 18, 2008 at 11:06 PM, Huebi <konrad....@googlemail.com> wrote:
>

Reply all
Reply to author
Forward
0 new messages