我正在尝试将文件从 j2me 应用程序发送到附近范围内的所有可用蓝牙设备。
我已搜索并显示范围内的设备,但无法将文件发送到该设备。在连接响应时,我得到响应代码为 211。
我添加了我的代码:
private void SendingFile() {
myForm.setTitle("Sending..");
for (int k = 0; k < myForm.size(); k++) {
myForm.delete(k);
}
myForm.append("Sending application..");
display.setCurrent(myForm);
try {
RemoteDevice remotedevice = (RemoteDevice) myVector.elementAt(devList.getSelectedIndex());
dAgent.searchServices(null, new UUID[]{new UUID(0x1105)}, remotedevice, this);
return;
} catch (BluetoothStateException bluetoothstateexception1) {
myForm.append("could not open bluetooth: " + bluetoothstateexception1.toString());
}
}
public void pauseApp() {
}
public void destroyApp(boolean flag) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == cmdScan) {
if (myForm == null) {
myForm = new Form("Scanning");
} else {
for (int i = 0; i < myForm.size(); i++) {
myForm.delete(i);
}
}
myForm.append("Scanning for bluetooth devices..");
Display.getDisplay(this).setCurrent(myForm);
if (devList == null) {
devList = new List("Devices", 3);
devList.addCommand(cmdSend);
devList.setCommandListener(this);
} else {
for (int j = 0; j < devList.size(); j++) {
devList.delete(j);
}
}
if (myVector == null) {
myVector = new Vector();
} else {
myVector.removeAllElements();
}
try {
if (localDev == null) {
localDev = LocalDevice.getLocalDevice();
localDev.setDiscoverable(DiscoveryAgent.GIAC);
dAgent = localDev.getDiscoveryAgent();
}
dAgent.startInquiry(DiscoveryAgent.GIAC, this);
} catch (BluetoothStateException bluetoothstateexception) {
myForm.append("Please check your bluetooth is turn-on");
}
}
if (command == cmdSend) {
SendingFile();
}
}
public void deviceDiscovered(RemoteDevice remotedevice, DeviceClass deviceclass) {
try {
devList.append(remotedevice.getFriendlyName(false), null);
} catch (IOException _ex) {
devList.append(remotedevice.getBluetoothAddress(), null);
}
myVector.addElement(remotedevice);
}
public void inquiryCompleted(int i) {
Display.getDisplay(this).setCurrent(devList);
}
public void servicesDiscovered(int i, ServiceRecord aservicerecord[]) {
servRecord = aservicerecord[0];
}
public void serviceSearchCompleted(int i, int j) {
if (j != 1) {
myForm.append("service search not completed: " + j);
}
try {
startServer();
myForm.append("Done");
} catch (Exception ex) {
myForm.append(ex.toString());
}
}
private void startServer() {
if (mServer != null) {
return;
}
mServer = new Thread(this);
mServer.start();
}
public void run() {
try {
boolean conFlag = true, FlagLoop = false;
myForm.deleteAll();
while (!FlagLoop) {
try {
connection = null;
String s = servRecord.getConnectionURL(0, false);
connection = (ClientSession) Connector.open(s);
} catch (IOException iex) {
myForm.append("IO Exce Con Create:".concat(iex.toString()));
continue;
} catch (Exception e) {
myForm.append("Exc Con Create:".concat(e.toString()));
continue;
}
CheckConnection();
}
} catch (Exception ex) {
}
}
private void CheckConnection() throws IOException {
try {
myForm.deleteAll();
myForm.append("Conn Check!!!");
HeaderSet header = connection.connect(null);
int responseCode = header.getResponseCode();
myForm.append("responseCode:" + responseCode);
if (responseCode != ResponseCodes.OBEX_HTTP_OK) {
throw new IOException();
}
myForm.append("After Response Check!!!");
Pushdata();
} catch (IOException ie) {
myForm.append("IO Exc in Checkconnection:".concat(ie.toString()));
} catch (Exception e) {
myForm.append("Exc in Checkconnection:".concat(e.toString()));
}
}
约瑟夫·拉吉