我关注了一篇关于制作一个可以找到蓝牙设备的应用程序并通过选择一个文件我们可以将其上传到手机的博客文章。
网络文章链接:http ://www.substanceofcode.com/2008/06/20/sending-files-to-mobile-phone-using-bluetooth-and-obex/
private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_uploadButtonActionPerformed
try {
// Get selected item from list
ListItem selectedItem = (ListItem) deviceList.getSelectedValue();
RemoteDevice device = selectedItem.getDevice();
// Build URL for the bluetooth device, note the port 9
String url = "btgoep://" + device.getBluetoothAddress() + ":9";
// Get file as bytes
FileInputStream stream = new FileInputStream(fileTextField.getText());
File f = new File(fileTextField.getText());
int size = (int) f.length();
byte[] file = new byte[size];
stream.read(file);
// Filename
String filename = f.getName();
// Trigger the task in a different thread so it won't block the UI
SendFileTask task = new SendFileTask(url, file, filename);
Thread thread = new Thread(task);
task.run();
} catch(Exception ex) {
System.err.println("Ex: " + ex.getMessage());
ex.printStackTrace();
}
现在,当运行应用程序时,我可以看到可用设备列表,我可以选择一个设备,也可以选择一个文件进行上传,但是当我点击发送时,它会抛出一个错误,它的内容是:
A socket operation was attempted to an unreachable network.
javax.bluetooth.BluetoothConnectionException: Failed to connect; [10051] A socket operation was attempted to an unreachable network.
at com.intel.bluetooth.BluetoothStackMicrosoft.connect(Native Method)
at com.intel.bluetooth.BluetoothStackMicrosoft.access$700(BluetoothStackMicrosoft.java:44)
at com.intel.bluetooth.BluetoothStackMicrosoft$ConnectThread.run(BluetoothStackMicrosoft.java:651)