[TinyTut] - Reading out the Phone's number

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

[TinyTut] - Reading out the Phone's number

Postby plusminus » Sun Dec 09, 2007 5:44 pm

[TinyTut] - Reading out the Phone's number


What you learn: You will learn how to read out the phonenumber of the device your application is running on.

Difficulty: 1 of 5 :)

:idea: Questions/Problems: Simply post below...

Description:
Nothing is easier to be done, if you know where to search for it :)
The SystemProperties provide a bunch of data of the current Phone-'Properties', like:
  • the operator-Name (i.e.: "T-Mobile" or "AT&T"
  • the ISO-Country-Name (i.e.: "us" or "de")
  • and of course your Phone-Number :!:
This is how to get these Strings into your Java-Code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String phoneNumber = android.os.SystemProperties.get(
  2.                 android.telephony.TelephonyProperties.PROPERTY_LINE1_NUMBER);
  3. String operatorISOCountry = android.os.SystemProperties.get(
  4.                 android.telephony.TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
  5. String operatorName =android.os.SystemProperties.get(
  6.                 android.telephony.TelephonyProperties.PROPERTY_OPERATOR_ALPHA);;
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

On the emulator this will return: "15555218135", "us" and "Android".

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

please update for 1.0

Postby eee333 » Fri Oct 03, 2008 7:36 pm

this code does not work in the current SDK
eee333
Freshman
Freshman
 
Posts: 9
Joined: Tue Mar 25, 2008 10:35 pm

Postby plusminus » Fri Oct 03, 2008 8:09 pm

Hello eee333,

have a look at this post, I think you should find a solution there:
:arrow: http://www.anddev.org/viewtopic.php?p=10711#10711

Please post here if you get it solved :!:

Best Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby gymshoe » Thu Nov 06, 2008 5:46 am

Your guidance was excellent +/-.

Per the link you provided I discovered:

The methods to retrieve the different parameters (imei, Line1Number, countryISO, etc.) are in the documentation under class TelephonyManager:

http://code.google.com/android/referenc ... nager.html

code example:

TelephonyManager mTelephonyMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = mTelephonyMgr.getDeviceId();
String phoneNumber=mTelephonyMgr.getLine1Number();
String country = mTelephonyMgr.getNetworkCountryISO();

etc.

Jim
gymshoe
Junior Developer
Junior Developer
 
Posts: 15
Joined: Wed Sep 10, 2008 6:07 am

Postby Artur79 » Sun Nov 09, 2008 6:23 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String country = mTelephonyMgr.getNetworkCountryISO();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

doesn't work for me, but following code is ok:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String country = mTelephonyMgr.getSimCountryIso();
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Artur79
Developer
Developer
 
Posts: 26
Joined: Fri Sep 26, 2008 12:53 pm

Postby c6bro » Tue Mar 03, 2009 1:59 pm

Just a quick one .

Which permmisions do I have to give in the Manifest
c6bro
Freshman
Freshman
 
Posts: 7
Joined: Fri Feb 27, 2009 12:10 pm

Top

Postby c6bro » Tue Mar 03, 2009 3:14 pm

Figured it our and got it working through the emulator but not when i load it on the phone ??

Only trying to retrive the phone number.

Any ideas . Do you have to manually store the phone number on the phone somewhere ?
c6bro
Freshman
Freshman
 
Posts: 7
Joined: Fri Feb 27, 2009 12:10 pm

Postby c6bro » Tue Mar 03, 2009 5:50 pm

I looked under about >Status and phone number and it says unknown so i guess its not reliable to get the phone number from the phone ??
c6bro
Freshman
Freshman
 
Posts: 7
Joined: Fri Feb 27, 2009 12:10 pm

Postby jasont » Tue Mar 10, 2009 7:46 pm

c6bro wrote:I looked under about >Status and phone number and it says unknown so i guess its not reliable to get the phone number from the phone ??


Correct.
jasont
Developer
Developer
 
Posts: 28
Joined: Mon Sep 22, 2008 6:39 pm
Location: California

Postby c6bro » Wed Mar 11, 2009 9:25 am

Thanks jasont for the response.

I guess I'm going to have to verify the phone number by using an sms gateway or something similar.

may be create registration app where they add there own phone number and it gets verified by sending an message to the number which is then intercepted on the way in to activate the app which I have created..

Really need to verify or get the genuine number in the phone.

anybody got any other ideas to verify mobile/cellular number
c6bro
Freshman
Freshman
 
Posts: 7
Joined: Fri Feb 27, 2009 12:10 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Google [Bot] and 10 guests