none
Get the phone number RRS feed

  • Question

  • Hi,

    I am trying to retrieve the telephone number from a Windows mobile 5/6 device but it doesn't work.
    I tried all the methods proposed on the internet :

    1) HRESULT SmsGetPhoneNumber ( SMS_ADDRESS* const psmsaAddress ); but this function doesn't work because in most cases the PhoneNumber is not stored in the SIM card.

    2) HRESULT SHGetPhoneNumber(LPTSTR szNumber, UINT cchNumber, UINT nLineNumber) sample provided in WM5/WM6 SDK (...\Windows Mobile 5.0 Pocket PC SDK\Samples\CPP\Win32\Getphonenumber) but in this case I have several options in function of the SIM card :

    a) it doesn't work
    b) It gives me a phone number that do not correspond to my phone number for instance with nLineNumber=1 I get the phone number of my parent's home and with nLineNumber =2 I get my sister's mobile phone number.

    I have tested only on HTC devices on WM5/WM6 with a GPRS/EDGE network in Europe.
    The application was signed with developper certificates and the PIN code was entered. Devices had been provisionned with developpers certificates.

    I have tested on the following phones with the SFR operator

    HTC P4350 (PocketPC)
    HTC blizzard (SmartPhone)
    HTC S620 (Smartphone)

    If some Windows mobile developper could answer...











    Thursday, January 31, 2008 11:17 AM

Answers

  • As far as I know the phone number is not stored on the sim card for GSM phones - only the network knows the numbers, and even then, this number is not transmitted in raw form (i.e. unencrypted) to the device as part of the GSM protocol. For some CDMA models with no separate SIM card (i.e. the sim is integrated into the device during manafucturing), yes, the phone number is stored locally and the code will be able to retrieve the number without asking the network for it. That's why your first function fails.

     

    However, it seems that the code works on the WM emulator; it gives a US number. For most other cases, the code will fail.

     

    The 2nd function that you give will retrieve the number from the phone book stored inside the SIM card based on their index. That's why you got your sister and mother's number. Btw, were those among the first few numbers you added into the SIM phone book just after you purchased it - I guess based on the index, 1 and 2 Smile

     

    Alternatively you can use SystemState.OwnerPhoneNumber (add reference to Microsoft.WindowsMobile.Status) which will return the phone number entered by the user in Start/Settings/Owner Information.

     

    In my project I take another approach: I will send an SMS to a predefined number when the application first starts, after which I will be able to retrieve the sender ID (which is the SIM card number).

     

    Hope this helps.

    Friday, February 1, 2008 2:34 PM

All replies

  • Ok I have my answer. It seems it's not always possible.
    Friday, February 1, 2008 9:06 AM
  • As far as I know the phone number is not stored on the sim card for GSM phones - only the network knows the numbers, and even then, this number is not transmitted in raw form (i.e. unencrypted) to the device as part of the GSM protocol. For some CDMA models with no separate SIM card (i.e. the sim is integrated into the device during manafucturing), yes, the phone number is stored locally and the code will be able to retrieve the number without asking the network for it. That's why your first function fails.

     

    However, it seems that the code works on the WM emulator; it gives a US number. For most other cases, the code will fail.

     

    The 2nd function that you give will retrieve the number from the phone book stored inside the SIM card based on their index. That's why you got your sister and mother's number. Btw, were those among the first few numbers you added into the SIM phone book just after you purchased it - I guess based on the index, 1 and 2 Smile

     

    Alternatively you can use SystemState.OwnerPhoneNumber (add reference to Microsoft.WindowsMobile.Status) which will return the phone number entered by the user in Start/Settings/Owner Information.

     

    In my project I take another approach: I will send an SMS to a predefined number when the application first starts, after which I will be able to retrieve the sender ID (which is the SIM card number).

     

    Hope this helps.

    Friday, February 1, 2008 2:34 PM
  • hi Smartdev75

    I am trying to get phone number but i am not getting.

    I have used following code

    PhoneAddress phoneAddress = new PhoneAddress();

                Byte[] buffer = new Byte[516];
                fixed (byte* pAddr = buffer)
                {
               
                    IntPtr res = SmsGetPhoneNumber((IntPtr)pAddr);

                    byte* pCurrent = pAddr;

                    if (res == IntPtr.Zero)
                    {
                        phoneAddress.AddressType = (AddressType)Marshal.ReadInt32((IntPtr)pCurrent);
                        pCurrent += Marshal.SizeOf(phoneAddress.AddressType);
                        phoneAddress.Address = Marshal.PtrToStringUni((IntPtr)pCurrent);
                    }

                }

    on emulator it is working fine but i have deployed on my HTC 3400 mobile which GSM sim it is not working.

    Please help me.
    Thursday, April 17, 2008 6:17 AM
  • Generally It's not possible to retrieve phone number ...
    The function may work on some device but you won't be able to generalize it.
    On all devices I have tested it has never worked.


    Vincent Richomme

    Thursday, April 17, 2008 1:15 PM
  • ok.very cool.

     

    Idea

     

    Thursday, June 19, 2008 1:55 AM
  • 3 years later I have a question, maybe with some luck I'll get an answer. Regarding the: "In my project I take another approach: I will send an SMS to a predefined number when the application first starts, after which I will be able to retrieve the sender ID (which is the SIM card number).": How can you get the sender Id after you sent an SMS (with, I assume, is done with SMSSendMessage)?

     

    TIA,

    MeCoco

    Monday, May 9, 2011 12:34 PM