我已经关注了一篇关于制作能够找到蓝牙设备的应用程序的博客文章,并选择了一个我们可以将其上传到手机的文件。
网络文章链接: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)
答案 0 :(得分:0)
我在Windows 7,64位上面临同样的问题,在我从蓝牙设备列表中删除设备然后再次配对后问题就消失了。