Hello, I am a newbe in J2ME and Bluetooth. I am trying to run an example I found on the net , but not successfull!! And I am getting frustrated because I need to establish a connection via bluetooth to access some data in a Data base!! Which would be the best connection type?? I am lost too because I didn´t find anywhere explaining where do I find the UUID?? neither the host neither the port in btspp://host:port;paramete
rs.
Here is the example I am trying to run!!!
Note that I didn´t change the UUID and host and port because I don´t know!!! Maybe that´s because it´s not working??
When I execute it, it just opens a black screen with nothing. I am testing it on the Series 60 MIDP emulator of NOKIA. Can anyone help me!!!!!
If anyone has a connection via bluetooth with a data base, I would appreciate too!!
BluetoothMIDlet
==========================
==========
==========
==========
=====
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*
;
import javax.microedition.midlet.
*;
import javax.bluetooth.*;
public class BluetoothMIDlet extends MIDlet implements Runnable, CommandListener {
public BluetoothMIDlet(){}
public void startApp() throws MIDletStateChangeException
{
new Thread(this).start();
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){}
public void run(){}
public void commandAction (Command c, Displayable d){
notifyDestroyed();}
}
==========================
==========
==========
==========
=====
HelloClient
==========================
==========
==========
==========
=====
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*
;
import javax.microedition.midlet.
*;
import javax.bluetooth.*;
public class HelloClient extends BluetoothMIDlet {
public void run(){
Form f = new Form("Cliente");
f.addCommand(new Command("Sair", Command.EXIT,1));
f.setCommandListener(this)
;
Display.getDisplay(this).s
etCurrent(
f);
try {
LocalDevice local = LocalDevice.getLocalDevice
();
DiscoveryAgent agent = local.getDiscoveryAgent();
String connString = agent.selectService(
new UUID("86b4d249fb8844d6a756
ec265dd1f6
a3", false),
ServiceRecord.NOAUTHENTICA
TE_NOENCRY
PT, false);
if (connString != null){
try{
StreamConnection conn = (StreamConnection)
Connector.open(connString)
;
OutputStream out = conn.openOutputStream();
out.write("Esta menssagem é de teste".getBytes());
out.close();
conn.close();
f.append("Menssagem enviada corretamente");
}
catch (IOException e){
f.append("IOException:" + e.getMessage());
}
}
else{
f.append("Não foi possivel localizar o servico");
}
}catch (BluetoothStateException e){
f.append("BluetoothStateEx
ception: ");
f.append(e.getMessage());
}
}
}
==========================
==========
==========
==========
=====
HelloServer
==========================
==========
==========
==========
======
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*
;
import javax.microedition.midlet.
*;
import javax.bluetooth.*;
public class HelloServer extends BluetoothMIDlet {
public void run(){
Form f = new Form("Servidor");
f.addCommand(new Command("Sair",Command.EXI
T, 1));
f.setCommandListener(this)
;
Display.getDisplay(this).s
etCurrent(
f);
try{
LocalDevice local = LocalDevice.getLocalDevice
();
if (!local.setDiscoverable(Di
scoveryAge
nt.GIAC)){
f.append("Falha ao mudar para modo Discoverable");
return;
}
StreamConnectionNotifier notifier = (StreamConnectionNotifier)
Connector.open("btspp://lo
calhost:"+
"86b4d249f
b8844d6a75
6ec256dd1f
6a3");
StreamConnection conn = notifier.acceptAndOpen();
InputStream in = conn.openInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
int data;
while ((data=in.read()) != -1) {
out.write(data);
}
f.append(out.toString());
in.close();
conn.close();
notifier.close();
}catch (BluetoothStateException e){
f.append("BluetoothStateEx
ception:"+
e.getMessa
ge());
}catch (IOException e){
f.append("IOException:"+e.
getMessage
());
}
}
}
==========================
==========
==========
==========
======