hi there
how i can make a java application to descover for bluetooth devices and send message to it
wad -1 Newbie Poster
wad -1 Newbie Poster
that is my j2me server application
i wonna do it in java program
import java.util.Vector;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* @author home
*/
public class me2 extends MIDlet implements Runnable,DiscoveryListener,CommandListener{
Vector de=new Vector();
Vector se=new Vector();
Form f;
DiscoveryAgent disa;
LocalDevice local;
String pr="";
Ticker t = new Ticker("Search..........");
int btcount;
List l;
public void startApp() {
try {
f = new Form("new");
//Ticker t = new Ticker("new");
f.addCommand(new Command("Discover", Command.OK, 1));
f.addCommand(new Command("Cancel", Command.EXIT, 1));
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);
} catch (Exception e) {
System.out.println(e);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void run() {
try {
btcount=0;
f.setTicker(t);
local = LocalDevice.getLocalDevice();
disa = local.getDiscoveryAgent();
disa.startInquiry(DiscoveryAgent.GIAC, this);
} catch (Exception e) {
System.out.println(e);
}
}
public void deviceDiscovered(RemoteDevice bt, DeviceClass cod) {
de.addElement(bt);
btcount++;
}
public void servicesDiscovered(int arg0, ServiceRecord[] sr) {
}
public void serviceSearchCompleted(int arg0, int arg1) {
}
public void inquiryCompleted(int arg0) {
if(de.isEmpty())
f.setTicker(new Ticker("no devices found"));
else
f.setTicker(new Ticker("found Devices"));
for(int i=0;i<de.size();i++){
try {
f.append(((RemoteDevice) de.elementAt(i)).getFriendlyName(true));
f.append(((RemoteDevice) de.elementAt(i)).getBluetoothAddress()+"\n");
} catch (Exception e) {
System.out.println(e);
}
f.setTicker(new Ticker("found "+btcount+" devices"));
}
de.removeAllElements();
}
public void commandAction(Command c, Displayable arg1) {
switch(c.getCommandType()){
case Command.OK:
f.deleteAll();
run();
break;
case Command.EXIT:
notifyDestroyed();
break;
default:
f.append("errrrrrrrre");
}
}
}
Kamila1988 0 Newbie Poster
It's not working -> "Error Application"
In what program did you compile this?
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.