1 / 36

Cosc 4730

Cosc 4730. Blackberry Wireless Message Service (WMA) 1.0/2.0. Introduction. Wireless messaging protocols predate JavaME , Android, Blackberry IP over cellular networks (most cell phone networks) Developed for Pagers and now used for call control. Wireless Messaging services

lida
Télécharger la présentation

Cosc 4730

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cosc4730 Blackberry Wireless Message Service (WMA) 1.0/2.0

  2. Introduction • Wireless messaging protocols predate • JavaME, Android, Blackberry • IP over cellular networks (most cell phone networks) • Developed for Pagers and now used for call control. • Wireless Messaging services • Major: SMS, Cell Broadcast (SMS-CB), MMS

  3. SMS • Short message service (ie texting) • Developed in 1985 by Global System for mobile (GSM) • All major terrestrial cellular network support it in some form. • 160 characters compressed into 140 bytes • There is a binary format as well (not MMS) • routed by SMS center (SMSC) • No guarantee of delivery. • Can be address to a port (on a device), so different applications can receive the sms message. • CDMA (most north American carriers) may not use port numbers

  4. MMS • Multimedia Messaging Service • Works on top of a number of wireless protocols • SMS or TCP/IP • Uses same ideas as email • message subject, body, multiple messages parts • multiple receipts as well. • Uses MMS Center to route messages. • Problems, newer not everyone device supports it • Carriers can't agree on MMS, so may not route between Cell Carriers either.

  5. SMB-CB • Short Message Service Cell Broadcast • Very new, not generally available. • May never be available to general public. • it's a point to area (1 to many) protocol • Allows you send a message to an area (such a geographic region or city) • Weather service, alerts, that sort of thing. (advertizing?) • message is 82 bytes, text or binary • can be concatenated a mechanism to deliver longer messages.

  6. WMA, a required optional package • Even though WMA is an optional package with regard to the Java ME as a whole, its presence is mandatory on handsets that claim to comply with JSR 185, the Java Technology for the Wireless Industry (JTWI) specification, and with JSR 248, the new Mobile Service Architecture (MSA) for CLDC. • JTWI defines minimum and common characteristics that all compliant handsets must provide; it mandates support for WMA 1.1, but not WMA 2.0. MSA continues the evolution of mobile architectures and specifies WMA 2.0 to be a mandatory package.

  7. Wireless Message API • Defined by JSR 120 (WMA 1.0), JSR 000120 maintenace (WMA 1.1), and JSR 205 (WMA 2.0) • package: javax.wireless.messaging • Uses GCF, MessageConnection extends Connection

  8. GCF Entire GCF for MIDP 2.0, http://developers.sun.com/mobility/midp/ttips/gcfcs/

  9. Message • The superclass for all WMA messages • provides interface for timestamps and addressing • TextMessage • interface for SMS message with text • BinaryMessage • interface for SMS with binary payload • MessageListener • listener for your app for incoming messages. • WMA 2.0 only • MultipartMessage interface to an MMS message with one or more message parts • MessagePart a single part of a message, used when composing or parsing MMS messages.

  10. WMA 2.0 supported Protocol • WMA 2.0 Supported Protocol Adapters and StandardsSupport for WMA protocol adapters is based on the following standards: • Short Messaging System as defined in the Global System for Mobile Communications (GSM) 03.40 standard • Cell Broadcast Service as defined in the Global System for Mobile Communications (GSM) 03.41 standard • Short Messaging System as defined in the Code Division Multiple Access (CDMA) IS-637 standard • Multimedia Messaging Services and the Protocol Data Unit (PDU) structure as defined in the WAP-209-MMS-Encapsulation standard

  11. Connector • protocol://recipient:port • protocol • mms for MMS message, sms for SMS message, and cbs for SMS-CB message • recipient • normally a phone number, short code or email address • if empty, then for receiving messages • port • port number, numeric for SMS and SMS-CB, alphanumeric string for MMS • May be left off or use 0 as well, not necessary for CDMA networks.

  12. Connector Examples • Examples of client connection URLs: • (MessageConnection)Connector.open ("sms://+15121234567:5000"); • (MessageConnection)Connector.open ("mms://+15121234567: com.j2medeveloper.MyMmsApp"); • No example for cbs is included, as cbs supports only server connections. • Examples of server connection URLs: • (MessageConnection)Connector.open("sms://:5000"); • (MessageConnection)Connector.open("mms://:com.j2medeveloper.MyMmsApp"); • (MessageConnection)Connector.open("cbs://:6000");

  13. Application IDs and Port Numbers • Application IDs identify the receiving application on a handset. • For example, in the two URLs sms://+5121234567:5000 and mms://+5121234567:com.j2medeveloper.MyMmsApp, the number 5000 and the string com.j2medeveloper.MyMmsApp are both application identifiers. • In sms and cbs, applications are identified by port numbers, similarly to how port numbers are used for TCP and UDP connections. • In mms, applications are identified by a string that typically is a fully qualified name such as com.j2medeveloper.MyMmsApp rather than a port number. • Note that a port number takes space, typically 16 bits, away from the actual content of a short message. • MMS application IDs, which can't exceed 32 characters in length, are optionally included as part of the multipart Content-Type message header. Creating an MMS server connection that specifies the application ID com.j2medeveloper.MyMmsApp will cause two parameters to be added to the value of the Content-Type message header:Application-ID=com.j2medeveloper.MyMmsApp;Reply-To-Application-ID= com.j2medeveloper.MyMmsApp

  14. Application IDs and Port Numbers (2) • When a server connection is opened, a port number or application ID is specified (depending on the protocol used). A client wanting to send a message to that server application must indicate that same port number or application ID. The first application to bind to a given port number or application ID gets it, and attempting to bind to an already reserved local port number or application ID throws an IOException that your code must handle appropriately. • You can pick a random port number to use from the private/dynamic port range 49152-65635; the range 0-49151 is used by privileged applications or user applications such as WAP; refer to the WMA 2.0 specification for more information on which ones you should avoid. • You can reserve your own port number for your application by contacting the Internet Assigned Numbers Authority (IANA). • Note that sending a message to a handset without specifying a port number or application ID to identify an application typically causes that message to be delivered to the handset's default viewer application.

  15. Creating a message mc = (MessageConnection)Connector.open ("sms://5121234567:5000"); TextMessage tm = (TextMessage) mc.newMessage( MessageConnection.TEXT_MESSAGE); • TEXT_MESSAGE for a TextMessage (sms) • BINARY_Message for a binaryMessage (binary sms) • MULTIPART_MESSAGE for a MultipartMessage (mms)

  16. Sending a sms message example void sendMessage() { MessageConnection mc = null; //open the connector first String url = "sms://"+ address.getText()+":"+port.getText(); try { mc = (MessageConnection) Connector.open(url); } catch (IOException e) { mc = null; return; //failed to open. } //now create the text message TextMessagemsg = (TextMessage) mc.newMessage(MessageConnection.TEXT_MESSAGE, url); msg.setPayloadText(sendText.getText()); //now send the message try { mc.send(msg); } catch (Exception e) { System.out.println("Failed to send message"); } //clean up msg = null; url = null; try { mc.close(); } catch (IOException e) { mc = null; } }

  17. Receiving a sms message • TextMessagemsg = mc.receive() //assume sms here • This waits for a message. • This is a blocking read • Meaning the program will stop and wait • receive should be on it's own thread, instead of the default thread.

  18. Receiving example //Using generic message, so I can get mms later on. try { MessageConnectionmsgConn = (MessageConnection) Connector.open("sms://:" + port.getText()); Message m = msgConn.receive(); receivedMessage(m); } catch (IOExceptionioe) { System.out.println("Failed to open or receive the message"); }

  19. Receiving example (2) public void receivedMessage(Message m) { //address is return address String address = m.getAddress(); String msg = null; if ( m instanceofTextMessage ) { TextMessage tm = (TextMessage) m; msg = tm.getPayloadText(); //msg now contains the sms message. } else … }

  20. Blackberry Simulators • Sending between two simulators • http://supportforums.blackberry.com/t5/Testing-and-Deployment/Send-SMS-text-messages-between-two-BlackBerry-Smartphone/ta-p/445990 • Setup to simulators to do the work. One you will have to start manually. • OR • In setup, set source and destination port to the same port, which redirects all output text messages, back to the simulator. I used port 1212.

  21. Blackberry Simulators (2) • In the example code, setting the source and destination port to the same, means the address is not really important. But allows you to test. • In debug/Run configuration ->simulator select the Network tab. Set SMS source/destination port. Also the phone number if you want.

  22. mms message

  23. The MultipartMessage Interface • The MultipartMessagesubinterface represents a message that consists of multiple parts, typically an MMS-based multimedia message. This interface defines a container of one or more MessageParts, and provides methods to manage the sender and recipient addresses, the message's headers, the "start message" content ID, and the message's parts: • booleanaddAddress(String type, String address); • void addMessagePart(MessagePartmessagePart) throws SizeExceededException; • String getAddress(); • String[] getAddresses(String type); • String getHeader(String headerField); • MessagePartgetMessagePart(String contentID); • MessagePart[] getMessageParts(); • String getStartContentId(); • String getSubject(); • booleanremoveAddress(String type, String address); • void removeAddresses(); • void removeAddresses(String type); • booleanremoveMessagePart(MessagePartmessagePart); • booleanremoveMessagePartId(String contentID); • booleanremoveMessagePartLocation(String contentLocation); • void setAddress(String address); • void setHeader(String headerField, String headerValue); • void setStartContentId(String contentID); • void setSubject(String subject);

  24. The MessagePart Class • The MultipartMessage interface represents the multimedia message and its headers, while a MessagePart class instance represents each individual MIME part. •  As its name suggests, MessagePart represents one part of a message. In addition to various constructors, this class provides methods to retrieve the content, and information about the content: • MessagePart(byte[] contents, int offset, int length, String mimeType, String contentId, String contentLocation, String encoding) throws SizeExceededException; • MessagePart(byte[] contents, String mimeType, String contentId, String contentLocation, String encoding) throws SizeExceededException; • MessagePart(InputStream is, String mimeType, String contentId, String contentLocation, String encoding) throws IOException, SizeExceededException; • public byte[] getContent(); • public InputStreamgetContentAsStream(); • public String getContentID(); • public String getContentLocation(); • public String getEncoding(); • public intgetLength(); • public String getMIMEType();

  25. example MessagePart public final static String MIMETYPE_TEXT_PLAIN = "text/plain"; public final static String MIMETYPE_IMAGE_PNG = "image/png"; MessageParttextMessagePart, imageMessagePart; try { // Create a text/plain part String textContent = "Hello world"; String textContentId = "text_hello"; String textContentLocation = "/helloworld.txt"; textMessagePart = new MessagePart( textContent.getBytes(), 0, textContent.length(), MIMETYPE_TEXT_PLAIN, textContentId, textContentLocation, null); // Create an image/png part InputStreamimageContent; String imageContentId = "img_hello"; String imageContentLocation = "/helloworld.png"; imageContent = getClass().getResourceAsStream (imageContentLocation); imageMessagePart = new MessagePart( imageContent, MIMETYPE_IMAGE_PNG, imageContentId, imageContentLocation, null); } catch (SizeExceededException see) { // Handle exception } catch (IOExceptionioe) { // Handle exception }

  26. send mms message MessageConnection c = null; String address = "mms://"+receiver+":"+appId; try { c = (MessageConnection) Connector.open(address); MutiplartMessagempm = (MultipartMessage)c.newMessage(MessageConnection.MULTIPART_MESSAGE); //mpm.addAddress("to", to); mpm.address("cc", cc); mpm.address("bcc",bcc); mpm.setSubject("Test mms message"); //mpm.setHeader("X-Mms-Priority",priority); //"high", "normal", "low" mpm.addMessagePart(textMessagePart); mpm.addMessagePart(imageMesssagePart); //now ready and send the mms c.send(mpm); } catch(Execption e) { /* deal with exception */}

  27. receive mss • create the connector and set to receive MessageConnection c = (MessageConnection) Connector.open("mms://:" + appId); Message msg = null; msg.c.receive(); //blocking read, use threads if (msginstanceofMultipartMessage) { //process the MessageParts MutipartMessagempm = (MultipartMessage)msg; MessageParts[] parts = mpm.getMessageParts(); if (parts != null) { //deal with the message parts. } }

  28. Capturing messages. • Two ways to ensure your app can read all messages. • Have the app start at boot and don’t use the mainscreen until you need to display to the user. • You lose any screen effects, but you app runs in the background, launching at boot means that your app will always be running. • Use the push registry. Except it is for Midlets, not applications.

  29. push registry • Allows to start your MIDlet when receiving a msg or socket connection • example: (in MIDlet-Permissions entry) MIDlet-Push1: socket://:7: edu.cs4730.EchoMIDlet, * • echo server, answer from any ip number MIDlet-Push2: socket://:80: edu.cs4730.HttpMIDlet, 192.168.1.128 • http server, but only from 192.168.1.128 MIDlet-Push3:sms://:1234: edu.cs4755.smsMIDlet, +1123456???? • text message, from phone number 1 (123) 456-*

  30. Dynamic Registration • As example: • MIDlet-Push3:sms://:1234: edu.cs4730.smsMIDlet,* • PushRegistry.registerConnection("sms://:1234", “edu.cs4730.smsMIDlet", "*"); • To unregister • PushRegistry.unregisterConnection("sms://1234");

  31. Getting the message. • So when the System launches your app, you need to get the message • Use the ListConnections Method //get the message "end points" String[] connections = PushRegistry.listConnections(true); if (connections != null && connections.length >0) //process the messages one at a time for (inti=0; i<connections.length; i++) { c = (MessageConnection) Connector.open (connections[i]); Message m = c.receive(); //now deal the message } }

  32. Blackberry extras • BB packages which provide extensions that allow you to listen to OUT BOUND messages. • This are only accessible by signed applications • net.rim.blackberry.api.mms • net.rim.blackberry.api.sms • Fully implements WMA 2.0 (including push registry) • includes email and blackberry messager. • net.rim.blackberry.api.invoke • provides allows third-party applications to remotely invoke internal (blackberry) applications • net.rim.blackberry.api.push • Provides client-side push applications, that uses the BlackBerry Push API Frameworks, with connectivity management functionalities.

  33. Blackberry SMS limitations • Not able to access the sms folders. • Can only get the sms messages as they arrive, at least in OS 4.7.X and below (unknown with OS 5.0.0+).

  34. Blackberry MMS • It is not currently possible to listen for all incoming MMS messages.  The applicationID of the sending and listening application must match. • Mark Sohm, BlackBerry Development Advisor,www.BlackBerryDeveloper.com • but • Sending the MMS message with a blank/empty application ID should allow it to show up in the Messages application (user's Inbox). • Mark Sohm, BlackBerry Development Advisor,www.BlackBerryDeveloper.com

  35. References • Besides the books • Several slides copy directly from http://developers.sun.com/mobility/midp/articles/wma2/ (noted in notes section of slides) • Blackberry • http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_listen_for_SMS_messages.html?nodeid=1357551&vernum=0 • http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/What_Is_-_Application_is_not_notified_when_new_messages_arrive.html?nodeid=800434&vernum=0 • http://docs.blackberry.com/en/developers/deliverables/11938/Using_custom_messages_folders_511381_11.jsp

  36. Q A &

More Related