Getting Device Phone Number

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

Hi

I'm trying to get the Phone Number that the device uses to make outgoing
calls.

I've found two methods but neither seem conclusive and can return blank on
some devices:

OpenNETCF.Phone.Sim.Sim sim = new OpenNETCF.Phone.Sim.Sim();
if (sim.OwnNumbers.Count > 0)
{
string sMyNumber = sim.OwnNumbers[0].Address;
labelPhoneNo.Text = sMyNumber;
}
else
{
labelPhoneNo.Text =
SystemState.OwnerPhoneNumber.ToString();

Is there a better solution?

Many Thanks!
 
The Own Numbers feature of the SIM card is up to the operator and usage
varies greatly. The SystemState.OwnerPhoneNumber relies on the user having
entered their user information when they setup the device.
To retrieve the actual device number you can either use TAPI, or in most
cases the SmsGetPhoneNumber method.

[DllImport("sms.dll")]
private static extern int SmsGetPhoneNumber(byte[] buffer);


usage:-


string phoneNumber = string.Empty;

byte[] buffer = new byte[516];
int hresult = SmsGetPhoneNumber(buffer);

if(hresult == 0)
{
phoneNumber = System.Text.Encoding.Unicode.GetString(buffer, 4,
buffer.Length - 4);
int nullIndex = phoneNumber.IndexOf("\0");
if(nullIndex > -1)
{
phoneNumber = phoneNumber.Substring(0, nullIndex);
}


Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility
 
Thanks Peter - I'll try that!

Peter Foot said:
The Own Numbers feature of the SIM card is up to the operator and usage
varies greatly. The SystemState.OwnerPhoneNumber relies on the user having
entered their user information when they setup the device.
To retrieve the actual device number you can either use TAPI, or in most
cases the SmsGetPhoneNumber method.

[DllImport("sms.dll")]
private static extern int SmsGetPhoneNumber(byte[] buffer);


usage:-


string phoneNumber = string.Empty;

byte[] buffer = new byte[516];
int hresult = SmsGetPhoneNumber(buffer);

if(hresult == 0)
{
phoneNumber = System.Text.Encoding.Unicode.GetString(buffer, 4,
buffer.Length - 4);
int nullIndex = phoneNumber.IndexOf("\0");
if(nullIndex > -1)
{
phoneNumber = phoneNumber.Substring(0, nullIndex);
}


Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

Matt said:
Hi

I'm trying to get the Phone Number that the device uses to make outgoing
calls.

I've found two methods but neither seem conclusive and can return blank on
some devices:

OpenNETCF.Phone.Sim.Sim sim = new OpenNETCF.Phone.Sim.Sim();
if (sim.OwnNumbers.Count > 0)
{
string sMyNumber = sim.OwnNumbers[0].Address;
labelPhoneNo.Text = sMyNumber;
}
else
{
labelPhoneNo.Text =
SystemState.OwnerPhoneNumber.ToString();

Is there a better solution?

Many Thanks!
 
Hi Peter,

I tried that but "SmsGetPhoneNumber" returns a large negative number
(-2147467259) so the routine fails :(

Could you point me in the direction of the TAPI solution?

Thanks

Matt

Matt said:
Thanks Peter - I'll try that!

Peter Foot said:
The Own Numbers feature of the SIM card is up to the operator and usage
varies greatly. The SystemState.OwnerPhoneNumber relies on the user having
entered their user information when they setup the device.
To retrieve the actual device number you can either use TAPI, or in most
cases the SmsGetPhoneNumber method.

[DllImport("sms.dll")]
private static extern int SmsGetPhoneNumber(byte[] buffer);


usage:-


string phoneNumber = string.Empty;

byte[] buffer = new byte[516];
int hresult = SmsGetPhoneNumber(buffer);

if(hresult == 0)
{
phoneNumber = System.Text.Encoding.Unicode.GetString(buffer, 4,
buffer.Length - 4);
int nullIndex = phoneNumber.IndexOf("\0");
if(nullIndex > -1)
{
phoneNumber = phoneNumber.Substring(0, nullIndex);
}


Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

Matt said:
Hi

I'm trying to get the Phone Number that the device uses to make outgoing
calls.

I've found two methods but neither seem conclusive and can return blank on
some devices:

OpenNETCF.Phone.Sim.Sim sim = new OpenNETCF.Phone.Sim.Sim();
if (sim.OwnNumbers.Count > 0)
{
string sMyNumber = sim.OwnNumbers[0].Address;
labelPhoneNo.Text = sMyNumber;
}
else
{
labelPhoneNo.Text =
SystemState.OwnerPhoneNumber.ToString();

Is there a better solution?

Many Thanks!
 
See this:

http://msdn.microsoft.com/en-us/library/ms880645.aspx


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

Matt said:
Hi Peter,

I tried that but "SmsGetPhoneNumber" returns a large negative number
(-2147467259) so the routine fails :(

Could you point me in the direction of the TAPI solution?

Thanks

Matt

Matt said:
Thanks Peter - I'll try that!

Peter Foot said:
The Own Numbers feature of the SIM card is up to the operator and usage
varies greatly. The SystemState.OwnerPhoneNumber relies on the user
having
entered their user information when they setup the device.
To retrieve the actual device number you can either use TAPI, or in
most
cases the SmsGetPhoneNumber method.

[DllImport("sms.dll")]
private static extern int SmsGetPhoneNumber(byte[] buffer);


usage:-


string phoneNumber = string.Empty;

byte[] buffer = new byte[516];
int hresult = SmsGetPhoneNumber(buffer);

if(hresult == 0)
{
phoneNumber = System.Text.Encoding.Unicode.GetString(buffer, 4,
buffer.Length - 4);
int nullIndex = phoneNumber.IndexOf("\0");
if(nullIndex > -1)
{
phoneNumber = phoneNumber.Substring(0, nullIndex);
}


Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

Hi

I'm trying to get the Phone Number that the device uses to make
outgoing
calls.

I've found two methods but neither seem conclusive and can return
blank on
some devices:

OpenNETCF.Phone.Sim.Sim sim = new OpenNETCF.Phone.Sim.Sim();
if (sim.OwnNumbers.Count > 0)
{
string sMyNumber = sim.OwnNumbers[0].Address;
labelPhoneNo.Text = sMyNumber;
}
else
{
labelPhoneNo.Text =
SystemState.OwnerPhoneNumber.ToString();

Is there a better solution?

Many Thanks!
 
Back
Top