有没有人知道如何在API级别2.3.3的2个Android设备之间创建不安全的RFCOMM连接,同时使用任意声明的服务名称?(不是随机或更改服务名称,只是我自己定义的服务名称)
我试图在2个Android设备之间创建一个不安全的Rfcomm连接:Droid X2和华硕Transformer.我假设这两款设备都具有Android 2.3.3级别的功能,实际上可以使用不安全的Rfcomm.
当我尝试按照此处所述创建蓝牙连接时,使用now public createInsecureRfcommSocketToServiceRecord()和listenUsingInsecureRfcommWithServiceRecord(SERVICE,UUID),我得到一个报告:
java.io.IOException: Service discovery failed
at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:377)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201)
at com.s4d.bluenomad.DeviceConnections$ClientThread.run(DeviceConnections.java:406)
Run Code Online (Sandbox Code Playgroud)
我发现了一个相关的问题,即有人创建正常连接时会收到此错误并使用反射来调用私有方法.但是,我不知道现在的私有方法会对应于启动"不安全"连接.我尝试使用相关问题中提出的解决方案,但Android要求我配对设备,这正是我需要避免的.我确实需要不安全的方法.
我甚至尝试了这里概述的官方和黑客解决方案的组合
创建ServerThread以侦听连接
Log.i(TAG, "Constructing a ServerThread");
// Use a temporary object that is later assigned to serverSocket,
// because serverSocket is final
BluetoothServerSocket tmp = null;
try {
// MY_UUID is the app's UUID string, also used by the client code
tmp = btAdapter.listenUsingInsecureRfcommWithServiceRecord(SERVICE_NAME, SERVICE_UUID);
Log.i(TAG,"Started listening on insecure RFCOMM channel for service …Run Code Online (Sandbox Code Playgroud)