locked
SmsMessage.Send() fails on SAMSUNG devices RRS feed

  • Question

  • Hi,

    I am using SmsMessage class from Microsoft.WindowsMobile.PocketOutlook namespace to send the SMS from my application.

    I am facing the problem with SAMSUNG devices on which the SMS is not being sent.

    SmsMessage.Send() method generates the exception "Error sending Sms Message." with the following stackTrace :

    at Microsoft.WindowsMobile.PocketOutlook.MAPIUtilities.ThrowCorrectSmsException()

    at Microsoft.WindowsMobile.PocketOutlook.SmsMessage.Send()

    at SMSSample.Form1.mnuSend_Click()

    at System.Windows.Forms.MenuItem.OnClick()

    at System.Windows.Forms.Menu.ProcessMnuProc()

    at System.Windows.Forms.Form.WnProc()

    at System.Windows.Forms.Control._InternalWnProc()

    at Microsoft.AGL.Forms.EVL.EnterMainLoop()

    at System.Windows.Forms.Application.Run()

    at SMSSample.Program.Main()

     

    This particular problem is being seen only on SAMSUNG devices. I have not seen this behavior on any other models till now.

    Any Ideas why this method fails on SAMSUNG devices?

    Any help will be greatly appreciated.

    Thanks and Regards,

    Himanshu

     


    Himanshu chhaya Windows Mobile and Windows Phone 7 Developer
    Monday, April 11, 2011 12:52 PM

Answers

All replies

  • Hi,

    May I know the device model? I tried on Samsung omni earlier. But I dint face any problem on that.

    It might have blocked by carrier or by OEM application. Just there is a chance.

    Regards,

    Malleswar

    • Proposed as answer by Jesse Jiang Friday, April 29, 2011 3:11 AM
    • Marked as answer by Himanshu Chhaya Friday, April 29, 2011 5:17 AM
    Wednesday, April 13, 2011 4:27 AM
  • Hi,

    Malleswar,

    Thanks for reply.

    The problem seems to be on SAMSUNG OMNIA. I tried with very simple basic application which just sends sms with only one form which takes recipient number and sms body, but result is still the same. SmsMessage.Send() throws the same exception even in this basic application.

    In all other models, the SMS seems to be working fine. We have HTC Viva, HTC Touch, HTC Touch Diamond in house and in all of them SMS is working fine. I am not sure as to what is causing this behavior. I am not able to do much since the Send() method is failing. How do I solve the problem?

    Any Clues?

    Thanks and Regards,

    Himanshu

     

     

     


    Himanshu chhaya Windows Mobile and Windows Phone 7 Developer
    Wednesday, April 13, 2011 4:37 AM
  •  

    Hi Himanshu,

     

    How about the native sample code works on your driver. Please try this sample

    Windows Mobile 6 SDK\Samples\Common\CPP\Win32\CellCore\SMS

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 13, 2011 5:48 AM
  • Hi Himanshu,

    Is it giving the same problem with native code?

    Also look into this thread:

    http://social.msdn.microsoft.com/Forums/en/windowsmobiledev/thread/64313634-413f-4fe4-b9a8-193cfd74a983

    Regards,

    Malleswar

    Wednesday, April 13, 2011 1:17 PM
  • Hi,

    Jesse and Malleswar,

    Thanks for your replies.

    I am yet to test the native code sample on SAMSUNG OMNIA. But I have tested it on my HTC Touch and I observed that, The application does not send the SMS if I do not prefix the recipient number with Country code. I get the error everytime when I do not provide the country prefix. If I provide it, It sends SMS successfully. I remember that We do not need to give any country code in .NET CF Class SmsMessage. Without giving any country prefix, It works fine in case of SmsMessage. Why is this difference?

    @Malleswar : I went through the forum post available at the link provided by you. How can we select default SMS center in SmsMessage class? Since It is working on other devices, what are the chances that default SMS Center is not selected/set on that particular device(SAMSUNG OMNIA)? Are there any manual settings to do for that?

    I will test the native sample on the SAMSUNG OMNIA device and let you know.

    Thanks and Regards,

    Himanshu

     

     

     

     


    Himanshu chhaya Windows Mobile and Windows Phone 7 Developer
    Thursday, April 14, 2011 4:56 AM
  •  

    Hi milan83,

     

    As far as I know, if you want to add the country prefix to the number of a message in the native sample code. You need to change the

    smsaDestination.smsatAddressType as SMSAT_INTERNATIONAL;

     

    If this smsaDestination.smsatAddressType is SMSAT_NATIONAL. I think it will not add the prefix.

     

    In the sample of .NET Compact Framework, I think this setting is by default.

     

    You can get more information about SMS_ADDRESS_TYPE  from here

     

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 14, 2011 6:36 AM
  • Hi,

    Jesse,

    In the Native Sample, There is an option to select default SMS Center or Center of your choice. How can we do the same with SmsMessage class in C# .Net? The default SMS Center is already selected in case of SmsMessage class or what?

    Is not selection of default SMS Center be the problem behind SmsMessage.Send() not working on some devices like SAMSUNG OMNIA?

    If yes, then how to make sure that default SMS Center is selected? Is it possible to do in C# code?

    Thanks & Regards,

    Himanshu


    Himanshu chhaya Windows Mobile and Windows Phone 7 Developer
    Thursday, April 14, 2011 7:06 AM
  • Hi Himanshu,

     

    As far as I know, the SmsMessage.Send()  call the API SendSMSMessage in CEMAPI.DLL. In this function we can not set the SMS Center, because it only has three parameter. In the HelloSMS sample codes, it call the SmsSendMessage API, you can set the SMS Center in SMS_ADDRESS structure. However, you could not set this in SmsMessage.Send(), because you can not change the SMS_ADDRESS in this function.

     

    If you want to set the SMS Center as HelloSMS sample in C#, you can use P/Invoke to call SmsSendMessage API. Please follow these codes:

     

    private const string SMS_MSGTYPE_TEXT = "Microsoft Text SMS Protocol";
    private const int SMS_MODE_SEND = 2;
    
    // Open in send mode
    private const int SMSDE_GSM = 2;
    
    // Use standard GSM encoding; 
    private const int SMSAT_INTERNATIONAL = 1;
    
    // International number format
    private const int PS_MESSAGE_OPTION_NONE = 0;
    
    // No message options
    private const int PS_MESSAGE_CLASS0 = 0;
    
    // Show but do not store
    private const int PS_MESSAGE_CLASS1 = 1;
    
    // Store and show
    private const int PSRO_NONE = 0;
    
    // No replacements
    private const int SMS_OPTION_DELIVERY_NONE = 0;
    
    // No delivery options
    private const int SMS_MAX_ADDRESS_LENGTH = 256;
    
    // Max length of address
    
    [DllImport("sms.dll")]
    private static extern int SmsOpen(
    string ptsMessageProtocol,
    int dwMessageModes,
    ref IntPtr psmshHandle,
    int phMessageAvailableEvent);
    
    [DllImport("sms.dll")]
    private static extern int SmsSendMessage(
    IntPtr smshHandle,
    int psmsaSMSCAddress, 
    IntPtr psmsaDestinationAddress,
    int pstValidityPeriod,
    IntPtr pbData,
    int dwDataSize,
    IntPtr pbProviderSpecificData,
    int dwProviderSpecificDataSize,
    int smsdeDataEncoding,
    int dwOptions,
    int psmsmidMessageID);
    
    [DllImport("sms.dll")]
    private static extern int SmsClose(IntPtr smshHandle);
    
    [DllImport("coredll.dll")]
    private static extern IntPtr LocalAlloc(uint uFlags, uint uBytes); 
    
    [DllImport("coredll.dll")]
    internal static extern IntPtr LocalFree(IntPtr hMem);
    private static IntPtr AllocHGlobal(IntPtr cb) 
    {
    IntPtr hmem;
    hmem = LocalAlloc(0x40, (uint) cb);
    return hmem;
    }
    private static void FreeHGlobal(IntPtr hglobal)
    {
    LocalFree(hglobal);
    public static int SendSMS(string Number, string Message) 
    {
    int returnValue = 0;
    IntPtr smsHandle = new IntPtr(0);
    
    // Set address structure
    byte[] smsatAddressType = BitConverter.GetBytes(SMSAT_INTERNATIONAL);
    byte[] ptsAddress =Encoding.Unicode.GetBytes+(ServerNum) Encoding.Unicode.GetBytes(Number); //add SeverNum in this line
    byte[] smsAddressTag = new byte[smsatAddressType.Length + ptsAddress.Length];
    Array.Copy(smsatAddressType, 0, smsAddressTag, 0, smsatAddressType.Length);
    Array.Copy(ptsAddress, 0, smsAddressTag, smsatAddressType.Length, ptsAddress.Length);
    IntPtr smsAddress = AllocHGlobal((IntPtr)smsAddressTag.Length);
    Marshal.Copy(smsAddressTag, 0, smsAddress, smsAddressTag.Length);
    // Set provider data structure
    byte[] dwMessageOptions = BitConverter.GetBytes(PS_MESSAGE_OPTION_NONE);
    byte[] psMessageClass = BitConverter.GetBytes(PS_MESSAGE_CLASS1);
    byte[] psReplaceOption = BitConverter.GetBytes(PSRO_NONE);
    byte[] smsProviderDataTag = new byte[dwMessageOptions.Length +
    psMessageClass.Length + psReplaceOption.Length];
    Array.Copy(dwMessageOptions, 0, smsProviderDataTag, 0, dwMessageOptions.Length);
    Array.Copy(psMessageClass, 0, smsProviderDataTag, dwMessageOptions.Length,
    psMessageClass.Length);
    Array.Copy(psReplaceOption, 0, smsProviderDataTag, dwMessageOptions.Length +
    psMessageClass.Length, psReplaceOption.Length);
    IntPtr smsProviderData = AllocHGlobal((IntPtr) smsProviderDataTag.Length);
    Marshal.Copy(smsProviderDataTag, 0, smsProviderData, smsProviderDataTag.Length);
    // Set message
    // Encoding unicode = Encoding.Unicode;
    // Encoding utf8 = Encoding.ASCII;
    // byte[] smsMessageTag1 = Encoding.ASCII.GetBytes(Message);
    // byte[] smsMessageTag = Encoding.Convert(utf8,unicode,smsMessageTag1);
    byte[] smsMessageTag = Encoding.Unicode .GetBytes(Message);
    IntPtr smsMessage = AllocHGlobal((IntPtr)smsMessageTag.Length);
    Marshal.Copy(smsMessageTag, 0, smsMessage, smsMessageTag.Length);
    
    // Get handle
    if (0 != SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, ref smsHandle, 0))
    returnValue = -1; // Could not open
    )
    // Send message
    if (0 != SmsSendMessage(smsHandle, 0, smsAddress, 0,
    smsMessage, smsMessageTag.Length,
    smsProviderData, smsProviderDataTag.Length,
    SMSDE_GSM, SMS_OPTION_DELIVERY_NONE, 0))
    returnValue = -2;
    
    FreeHGlobal(smsMessage);
    FreeHGlobal(smsProviderData);
    FreeHGlobal(smsAddress);
    
    // Release handle
    if (0 != SmsClose(smsHandle))
    returnValue = -3;
    
    // Could not close
    
    return returnValue;
    }
    }
    }
    

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 20, 2011 6:41 AM
  • Hi,

    Jesse,

    Sorry for late reply. Actually I did not have the SAMSUNG OMNIA device with me so I managed to test the samples remotely using TeamViewer on SAMSUNG OMNIA, which took some time. 

    Anyways, Here are the findings:

    1. Native SDK Sample (HelloSMS) : When run on SAMSUNG OMNIA generates the message "There was a problem sending your message.". Meaning sending the SMS has failed.

    2. Managed Sample created by me : (Shows a simple form with two textboxes taking number and sms body with menu option "Send". When "Send" is pressed i am opening SMS Composer form with data filled in.) :  When run, does not open SMS Composer form but opens the "Account selection screen" similar to the screen opened when we click "Messaging" from start menu or launch "tmail.exe" from windows folder. And when I close this screen, I get the Error message "Native method call failed".

    Furthermore, In my HTC Touch, when I click on "Messaging", the "Account Selection screen" opens which has following options:

    1. SMS/MMS

    2. Outlook E-mail

    3. E-mail Sample

    4. New E-mail Account.

    But, In SAMSUNG OMNIA, There is no SMS/MMS option available..!!! I saw only "New E-mail Account" option. Can you tell why is that?

    Does that mean Native SMS functionality has been overridden?  SAMSUNG OMNIA has its own SMS application which is very different from WINDOWS MOBILE Native application.

    Even launching the tmail.exe from windows folder shows the screen with only one option "New E-mail Account" as I mentioned above.

    So what can I do in this situation? Any ideas?

    Thanks and regards,

    Himanshu

     

     


    Himanshu chhaya Windows Mobile and Windows Phone 7 Developer
    Thursday, April 28, 2011 10:07 AM
  • Hi Himanshu,

     

    I'm so sorry for that, this limitation is set by OEM, you can open a new thread in Samsung-omnia support forum. I hope you can get solution from there.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 29, 2011 3:14 AM
  • Hi,

    Jesse,

    Thanks for your support. I will see if I get anything at the link provided by you.

    Thanks again.


    Regards,

    Himanshu


    Himanshu chhaya Windows Mobile and Windows Phone 7 Developer
    Friday, April 29, 2011 5:13 AM