【问题标题】:send files from pc to mobile via bluetooth in java without pairing通过java中的蓝牙将文件从PC发送到手机而无需配对
【发布时间】:2012-09-20 08:58:44
【问题描述】:

我正在开发一个使用 java 将文件发送到周围设备的桌面应用程序。 已完成,但我有一个问题,当尝试开始发送操作时,移动设备中会出现一条配对消息。我的应用程序使用 bluecove 库。Bluecove 在其网站上有一个示例应用程序,用于通过蓝牙发送文件,发送时不需要配对files.从这里下载它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();

我的网址是:btgoep://001FDF08DEEC:9;authenticate=false;encrypt=false;master=false

我想知道我的应用程序和 bluecove 示例应用程序有什么区别。 提前谢谢。

【问题讨论】:

    标签: java bluetooth bluecove obex


    【解决方案1】:

    基于this,您可以在.net 中进行自动身份验证!

    根据我在 bluecove 的经验,您需要重写 RemoteDevice.authenticate() 函数并为服务器提供一个硬编码的 pin 号码,并使该号码可供客户端输入以进行身份​​验证! 使用这种方法您可以进行配对,但无需在服务器端手动输入!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多