我正在开发一个桌面应用程序,使用 java 将文件发送到周围的设备。 完成了,但我有一个问题,当发送操作试图开始时,配对消息出现在移动设备上。我的应用程序使用 bluecove 库。Bluecove 在其网站上有一个示例应用程序通过蓝牙发送文件,发送时不需要配对文件。从这里下载 http://www.bluecove.org/bluecove-examples/obex-install/push.jnlp
这是我将文件发送到蓝牙设备的代码:
Connection connection = Connector.open(btConnectionURL);
// connection obtained
// now, let's create a session and a headerset objects
ClientSession cs = (ClientSession) connection;
HeaderSet hsConnectReply = cs.connect(null);
if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
System.out.println("Error while connecting device");
return;
}
HeaderSet hs = cs.createHeaderSet();
hs.setHeader(HeaderSet.NAME, filename);
hs.setHeader(HeaderSet.TYPE,
new MimetypesFileTypeMap().getContentType(new File(filen)));
hs.setHeader(HeaderSet.LENGTH, new Long(file.length));
Operation putOperation = cs.put(hs);
OutputStream outputStream = putOperation.openOutputStream();
outputStream.write(file);
// file push complete
outputStream.close();
putOperation.close();
cs.disconnect(null);
connection.close();
我的 url 是:btgoep://001FDF08DEEC:9;authenticate=false;encrypt=false;master=false
我想知道我的应用程序和 bluecove 示例应用程序之间有什么区别。 提前致谢。
最佳答案
基于 this您可以在 .net 中进行自动身份验证!
根据我在 bluecove 中的经验,您需要重写 RemoteDevice.authenticate() 函数并为服务器提供一个硬编码的 pin 号码,并让客户端可以输入该号码以进行身份验证! 使用这种方法,您可以进行配对,但无需在服务器端手动输入!
关于java - 无需配对即可通过java中的蓝牙将文件从PC发送到手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12640611/