Call System SMS sending methods for various SMART platforms

Source: Internet
Author: User

In Android, the Code calls the system SMS sending interface as follows:

 

Uri smstouri = URI. parse ("smsto: // 10086 ");
Intent mintent = new intent (Android. content. Intent. action_sendto, smstouri );
Startactivity (mintent );

 

 

You can call the system SMS sending interface in Sybian as follows:

Csendui * sendappui = csendui: newlc ();
Cmessagedata * message = cmessagedata: newlc ();
Crichtext * richtext = crichtext: newl (ceikonenv: static ()-> systemparaformatlayerl (),
Ceikonenv: static ()-> systemcharformatlayerl ());
Cleanupstack: pushl (richtext );

// Message-> setsubjectl (& ksubject );
Richtext-> insertl (0, msgcontent); // append the message content here

Message-> setbodytextl (richtext );
Sendappui-> createandsendmessagel (ksenduimtmsmsuid, message, knulluid, etrue );

Cleanupstack: popanddestroy (3 );

Use tmail.exe for Windows lele.
Tmail.exe-service "SMS"-to "Number"-Body "content"
========================================================== ========================================
There are two types of text message sending applications for Windows Mobile. One is to call Windows Mobile's own SMS sending window to pass the mobile phone number of the recipient to this window, to send a text message (also called a window text message), call the API to send the text to a specified number, in this example, the sending method is imperceptible to the user (for the moment, it is called the imperceptible SMS. The following describes the implementation of these two methods.

Window text message:
Window text message implementation is relatively simple, you can directly use the following startup parameters to start the system's exe file, system. diagnostics. process. start ("tmail.exe", "-transport/" SMS/"-to/" "+ mobile phone number +"/"-body/" SMS content /""); however, after the message is sent, the SMS list page is displayed after you close the message sending window. You can use the findwind method in the closing event of the page, find the system text message window and close it.

Imperceptible SMS
1. Windows Mobile 5.0 and later versions
The imperceptible SMS interface is related to the mobile operating system version. If it is based on a Windows mobile5.0 device, it is easier to send text messages because Microsoft has encapsulated the underlying API for you, can be called directly to reference Microsoft. windows Mobile. pocketoutlook. after the DLL, use smsmessage smssend = new smsmessage (phone, SMS); smssend. send (); Method to send a short message.

2. Windows Mobile 2003 or Windows mobile2003se Device
In versions earlier than 5.0, although the current usage is relatively small, it was very difficult to send short messages on it two years ago. At that time, it really gave me a headache for a while, you need to encapsulate the underlying API and call it by yourself. Here I will post it for your reference.
Using system;
Using system. runtime. interopservices;
Using system. text;

Namespace smartsms
{
/// <Summary>
/// SMS sending program
/// </Summary>
Public class SMS
{
Public SMS ()
{
//
// Todo: add the constructor logic here
//
}
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 (number );
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; // cocould 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; // cocould not close

Return returnvalue;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.