Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java ME: Wireless Messaging and Bluetooth, Study notes of Mobile Computing

An overview of java me (mobile edition) and its use in wireless messaging and bluetooth technology. It covers the wireless messaging api (jsr205) for sending and receiving sms messages, as well as the basics of bluetooth, including discovering devices and services, and creating bluetooth clients and services. The document also includes examples of using the wma console in netbeans for sending and receiving messages, and creating a bluetooth service and client.

Typology: Study notes

2010/2011

Uploaded on 09/08/2011

rossi46
rossi46 🇬🇧

4.5

(10)

313 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 9
Java ME – Wireless Messaging and
Bluetooth
Markus A. Wolf
1
Application Development
for Mobile Devices
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download Java ME: Wireless Messaging and Bluetooth and more Study notes Mobile Computing in PDF only on Docsity!

Lecture 9

Java ME – Wireless Messaging and

Bluetooth

Markus A. Wolf

1

Application Development

for Mobile Devices

Lecture Overview

Wireless Messaging API

What is the WMA

Sending and receiving SMS messages

Bluetooth

What is Bluetooth

Discovering devices and services

Creating a Bluetooth service

Creating a Bluetooth client

SMS

SMS messages consist of short text messages

(normally up to 160 characters)

What are some of the advantages of SMS?

Cheap

Message is not lost if the receiving phone is

unavailable

Sent through a store-and-forward network

javax.wireless.messaging

Messages are sent and received using a MessageConnection The javax.wireless.messaging package contains classes for sending and receiving messages Message is an interface These are subinterfaces

Message Types

Messages can be of different types:

Text – message in text format. Normally 72

characters per SMS message

Binary – message in binary format. Normally limited

to 133 bytes per SMS message

Multipart – used to send MMS messages

Note that messages in text and binary format

can be longer than 72 character or 133 bytes

In this case, they are segmented by WMA and sent

separately

Sending Message Example

We will look at an example of a MIDlet that

sends an SMS message

Sending a message Receiving a message

Starting the WMA Console in NetBeans

Select Tools -> Java Platforms

Select the Wireless Toolkit Go to the Tools & Extensions tab Click the Open Utilities button

Starting the WMA Console in NetBeans

Select and click Launch

Message Sending Example

How do we know where to send the message

to?

When the emulator starts it is given a number

E.g. +

We will use a WMA Console to exchange messages,

which also has a number

The number identifies the device emulator

To send a message to a particular application, we

can use port numbers

E.g. +5550000:

SendMidlet

import javax.microedition.midlet.; import javax.microedition.lcdui.; import javax.wireless.messaging.; import javax.microedition.io.Connector; public class SendMidlet extends MIDlet implements CommandListener, Runnable{ private Form mForm; private StringItem lblMessage; private TextField txtDest, txtMsg; ... } Importing packages required for messaging Displays a success / failure message To specify the destination number For entering the message to be sent*

SendMidlet – commandAction()

public void commandAction(Command c, Displayable s) { if (c.getCommandType() == Command.EXIT) { notifyDestroyed(); } else { lblMessage.setText("Sending SMS..."); Thread t = new Thread(this); t.start(); } } Starts a new thread so that our GUI doesn’t hang when we send a message – this is why our MIDlet implements Runnable

SendMidlet – run()

public void run(){ try { MessageConnection conn = (MessageConnection) Connector.open("sms://" + txtDest.getString()); TextMessage txtMessage = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE); txtMessage.setPayloadText(txtMsg.getString()); conn.send(txtMessage); lblMessage.setText("SMS sent successfully"); conn.close(); } catch(Exception ex) { lblMessage.setText("Message could not be sent"); } } The Connector creates the correct connection for the given protocol We are sending an SMS in text format Sets the text to be sent Sends the message Whenever we deal with external resources, we should use try…catch

Message Receiving Example

Now an example of a MIDlet that receives an SMS

message

Sends a message Receives a message

ReceiveMidlet

import javax.microedition.midlet.; import javax.microedition.lcdui.; import javax.wireless.messaging.; import javax.microedition.io.Connector; public class ReceiveMidlet extends MIDlet implements CommandListener, Runnable{ private Form mForm; private StringItem lblMessage; private TextField txtPort; private boolean finished; ... } Importing packages required for messaging Displays received messages Used to keep displaying received messages until MIDlet is closed For entering the port to listen on*