Getting Device Phone Number

Discussion in 'Microsoft Dot NET Compact Framework' started by Matt, Apr 6, 2009.

  1. Matt

    Matt Guest

    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!
     
    Matt, Apr 6, 2009
    #1
    1. Advertisements

  2. Matt

    Peter Foot Guest

    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" <> wrote in message
    news:...
    > 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!
     
    Peter Foot, Apr 6, 2009
    #2
    1. Advertisements

  3. Matt

    Matt Guest

    Thanks Peter - I'll try that!

    "Peter Foot" wrote:

    > 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" <> wrote in message
    > news:...
    > > 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!

    >
    >
     
    Matt, Apr 6, 2009
    #3
  4. Matt

    Matt Guest

    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" wrote:

    > Thanks Peter - I'll try that!
    >
    > "Peter Foot" wrote:
    >
    > > 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" <> wrote in message
    > > news:...
    > > > 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!

    > >
    > >
     
    Matt, Apr 7, 2009
    #4
  5. 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" <> wrote in message
    news:...
    > 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" wrote:
    >
    >> Thanks Peter - I'll try that!
    >>
    >> "Peter Foot" wrote:
    >>
    >> > 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" <> wrote in message
    >> > news:...
    >> > > 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!
    >> >
    >> >
     
    Chris Tacke, eMVP, Apr 7, 2009
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    reading phone number or SIM card number

    Guest, Sep 17, 2005, in forum: Microsoft Dot NET Compact Framework
    Replies:
    0
    Views:
    294
    Guest
    Sep 17, 2005
  2. Replies:
    1
    Views:
    380
    Alex Feinman [MVP]
    Oct 4, 2005
  3. Jay

    Phone number of my device

    Jay, May 9, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    2
    Views:
    216
    Guest
    May 10, 2006
  4. Launch Phone App (cprog.exe) with a phone number

    , May 26, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    1
    Views:
    504
    Per Rasmussen
    May 29, 2006
  5. Venkat Polisetti

    Contact.ShowDialog() : Not dialing the phone when tapped on the phone number ...

    Venkat Polisetti, Jul 20, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    2
    Views:
    354
    Chani Johnson [MSFT]
    Sep 9, 2006
Loading...

Share This Page