Send and receive multimedia messages on Windows Mobile

Source: Internet
Author: User

One project involved sending and receiving of MMS, So I studied how to send and receive MMS on WM. The conclusion is very regrettable. The system did not provide such a direct interface, it is also difficult to find a work und, because on the WM platform, the MMS program is implemented by hardware vendors.
That is to say, I have to send and receive MMS from start to end.

Sending of MMS on one Wm

MMS is an application built on the WAP protocol. To send MMS, you must first establish a WAP connection on the device. (Do you have to establish a WAP connection? Do you have to follow the WAP protocol? In fact, it depends on the WAP Gateway and MMS server of the network service provider. For example, Guangzhou mobile provided support for sending MMS over HTTP some time ago, currently, Guangzhou Unicom supports WSP sending MMS in the net network ).
However, to ensure that our program can be more universal, it is best to select a WAP connection and use the WAP protocol to send it with WSP.

1. Http Transmission

In principle, as long as the gateway supports the WAP2.0 protocol, it can be sent over HTTP. when sending an HTTP request, first establish a TCP/IP connection with the gateway (currently, both Mobile and China Unicom's HTTP gateways are 10.0.0.172: 80), and then send a POST request. the following is a POST request successfully sent by Guangzhou mobile. (I don't know why it cannot be sent)

// Mmscname for MMS server, mobile for "http://mmsc.monternet.com", Unicom for "http://mmsc.myuni.com.cn"
String headerbuffer = "post http: //" + mmscname + "/HTTP/1.1/R/N ";
Headerbuffer + = "accept: image/PNG, image/GIF, image/X-xbitmap, image/JPEG, image/pjpeg, */R/N ";
// Gateway address, which is currently 10.0.0.172: 80
Headerbuffer + = "Host: 10.0.0.172: 80/R/N ";
Headerbuffer + = "X-Online-Host:" + mmscname + "/R/N ";
Headerbuffer + = "Pragma: No-Cache/R/N ";
Headerbuffer + = "cache-control: No-Cache/R/N ";
Headerbuffer + = "connection: keep-alive/R/N ";
Headerbuffer + = "Accept-encoding: deflate, Gzip/R/N ";
Headerbuffer + = "User-Agent: SAMSUNG-SGH-E908/netfront 3.2/WAP2.0 profile/MIDP-2.0 configuration/CLDC-1.1/R/N ";
Headerbuffer + = "accept: Application/vnd. WAP. MMS-message, image/vnd. WAP. wbmp, image/PNG, image/JPEG, image/GIF, text/X-imelody, text/X-imelody, application/X-Midi, audio/Midi, audio/mid, audio/X-mid, image/BMP, audio/MP3, audio/X-Midi, audio/AMR, application/vnd. smaf, application/vnd. WAP. MMS-message X-wap-profile: http://wap.samsungmobile.com/uaprof/e908_10.xml/r/n ";
// S_length indicates the length of the MMS package.
Headerbuffer + = "Content-Length:" + s_length + "/R/N ";
Headerbuffer + = "Content-Type: Application/vnd. WAP. MMS-message/R/n/R/N ";
// The MMS package data is received after/R/n.

After sending the message, wait for the gateway's response and return the 200 OK message, indicating that the MMS Message is successfully sent. Otherwise, the message fails to be sent. the cause of the failure may be that the HTTP header group is incorrect, or the MMS package is wrong, but the more likely cause is that the gateway does not support it.

2 WSP Transmission

WSP to send more complex, need to understand the wap wtp wsp this set of protocols. WAP-230-WSP-20010705-a, WAP-224-WTP-20010710-a these two documents have a detailed description.

After the WSP method is sent, the gateway returns results, but sometimes the parsed results indicate that the message is not sent successfully, but the recipient receives the MMS correctly. I don't know if WSP is sending or the MMS package group is faulty.

The gateway port used for sending data in WSP mode is 1920.

3. MMS Packaging

MMS has two packaging methods: Application/vnd. WAP. multipart. mixed, which is more complex than application/vnd. WAP. multipart. related. my MMS program is actually sending an attachment file to the recipient, so you only need application/vnd. WAP. multipart. the mixed method is enough, so I only studied this simple method.
Use application/vnd. WAP. multipart. as the name suggests, the MM assembled in the mixed mode is the order in which all messages are mixed together without time, there is no relationship between all the message content that mmscontent points to. If there is a relationship, it is the time sequence stored in mm, but there may be no time for displaying the message content. it is likely to be displayed once later.
In this way, you only need to enter some major keywords, and then connect the MMS attachment data.

The following is a simple MMS package.

// X-MMS-message-type (0x8c): m-send-req (0x80)
Byte * pcurpos = pbuffcontent;
* Pcurpos = 0x8c; pcurpos ++;
* Pcurpos = 0x80; pcurpos ++;

// ID
* Pcurpos = 0x98; pcurpos ++;
Char * pid = NULL;
GETID (& pid );
Strcpy (char *) pcurpos, pid );
Pcurpos + = strlen (PID );
* Pcurpos = 0x00; pcurpos ++;

// X-MMS-version (0x8d): V1.0 (0x90)
* Pcurpos = 0x8d; pcurpos ++;
* Pcurpos = 0x90; pcurpos ++;

// From
* Pcurpos = 0x89; pcurpos ++;
* Pcurpos = 0x01; pcurpos ++;
* Pcurpos = 0x81; pcurpos ++;

// To (0x97)
Tchar sztocombin [50];
_ Stprintf (sztocombin, _ T ("% S % s"), _ T ("+ 86"), szto, _ T ("/type = plmn "));
* Pcurpos = 0x97; pcurpos ++;
Char * PTO = NULL;
String_wchartombyte (sztocombin, & PTO );
Strcpy (char *) pcurpos, PTO );
Pcurpos + = strlen (PTO );
* Pcurpos = 0x00; pcurpos ++;

// Subject
* Pcurpos = 0x96; pcurpos ++;
Char * psubject = NULL;
String_wchartombyte (szsubject, & psubject );
// Psubject = "mmstest ";
Strcpy (char *) pcurpos, psubject );
Pcurpos + = strlen (psubject );
* Pcurpos = 0x00; pcurpos ++;

// Content-Type: Application/vnd. WAP. multipart. Mixed
* Pcurpos = 0x84; pcurpos ++;
* Pcurpos = 0xa3; pcurpos ++;

// Multipart, count
* Pcurpos = 0x01; pcurpos ++;

// Headerslen
* Pcurpos = 0x0f; pcurpos ++;

// Attachment data
Char * pattachdata = NULL;
String_wchartombyte (szxmldata, & pattachdata );

// Datalen, attachment Data Length
Int idatatextlen = strlen (pattachdata) + 1;
Int ibytelen = 0;
Byte * pdatalen = encodeuintvar (idatatextlen, ibytelen );
Strncpy (char *) pcurpos, (char *) pdatalen, ibytelen );
Pcurpos + = ibytelen;
// * Pcurpos = (unsigned char) idatatextlen; pcurpos ++;

// Headlen
* Pcurpos = 5 + _ tcslen (szxmlfilename); pcurpos ++;

// Uft-8
* Pcurpos = 0x83; pcurpos ++;
* Pcurpos = 0x85; pcurpos ++;

// Attach file name
Char * pattachfile = NULL;
String_wchartombyte (szxmlfilename, & pattachfile );
// Pattachfile = "phone. xml ";
Strcpy (char *) pcurpos, pattachfile );
Pcurpos + = strlen (pattachfile );
* Pcurpos = 0x00; pcurpos ++;

// Charset UTF-8
* Pcurpos = 0x81; pcurpos ++;
* Pcurpos = 0xea; pcurpos ++;

// Attach file content
Strcpy (char *) pcurpos, pattachdata );
Pcurpos + = strlen (pattachdata );
* Pcurpos = 0x00; pcurpos ++;

// Actual length of the MMS package
Ireallen = pcurpos-pbuffcontent;

Receiving of MMS on 2wm

I personally think that receiving MMS on Windows Mobile is more troublesome than sending it. because it is very troublesome to intercept MMS notifications, You have to compete with the system's built-in MMS program because if the system's built-in MMS program returns ack after receiving the MMS, if I have not received it, I cannot receive it.

1. Interception of MMS notifications.
MMS notification is actually a special text message, which cannot be seen in the inbox of the system. That is to say, it is definitely impossible to get this MMS notification message from the inbox using a common mapi.
I tried to use mapirule to intercept text messages and found that this notification message was not in that place.
I found a set of APIS (pushrouter_registerclient) on the Internet to intercept push messages. There is a sample in the SDK, but I tried it for two days and it never succeeded.
Later, RIL was used to intercept the ril_policy_message message and finally blocked the message, but I always thought this method was not good.
The MMS notification is actually a piece of compressed binary data, which contains the MMS sender, subject, and URL. this URL is actually the storage address of the MMS. parse the binary code and obtain the URL to retrieve the MMS.

2. MMS Retrieval
To obtain MMS, you also need to deal with the WAP Gateway. Naturally, you also need to establish a WAP network connection and establish a TCP/IP connection with the gateway (also 192.168.0.172: 80, send a GET request to the gateway.

Char szgetstring [max_path] = ""; // purlmbyte is the url mms address obtained in the previous step.
Sprintf (szgetstring, "Get % s HTTP/1.1/R/n/R/N", purlmbyte );

The gateway will respond to this GET request. If the request is sent successfully, the following response will be obtained:

HTTP/1.1 200 OK
Content-Type: Application/vnd. WAP. MMS-message
Content-Length: 1301
Connection: keep-alive
Proxy-connection: keep-alive
Keep-alive: timeout = 15, max = 49
Via: HTTP/1.1 SDJN-PS-WAP2-GW07 (infox-wisg, Huawei Technologies)
Server: mmsc-jn4-rsv.monternet.com
X-mmsc-MSG-from: MM1

??? 9kn4i0htkvr0 ??? 062117015591007101190? J =? +? ? + 8613207008167/type = plmn? 8615206300005/type = plmn? ? <Rdwnpb id = '20140901'/> ??????? ?? <Start>? Application/SMIL? L ??? <Phonebook> <node name = "¥ ????? ¥ ?? (¥ ??) "Cont =" 5551012

The plain text above is the HTTP header. If you see "200 OK", the message is successfully received. The MMS data is followed by two line breaks. You can retrieve the data and parse it.

3. If it is not finished, return an ACK to the MMS server. Otherwise, the MMS server will think that we have not received the MMS and will send another MMS notification.
Back to Ack is also post a request to the gateway.

 

Http://hi.baidu.com/gdoupanguoqing/blog/item/e772fcd00302b086a0ec9c05.html

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.