2

尽管已经写了很多关于这个主题的文章,但我仍然找不到针对我的具体问题的解决方案:

我正在尝试用一个简单的蓝牙设备连接三星 Galaxy SIII。当我使用手机的蓝牙设置(不需要 PIN)将这两者配对时,它可以工作。但是如果设备之前没有手动配对,我会收到以下异常:

java.io.IOException: Service discovery failed
at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:462)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:240)
at com.concept.proiv.BluetoothConnection$1.run(BluetoothConnection.java:84)
at java.lang.Thread.run(Thread.java:856)

相关代码:

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) ...
if (!mBluetoothAdapter.isEnabled()) ...

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice("00:0A:3A:2F:7C:1A");
try
{
    btSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
}
catch (IOException e) ... - WORKING
mBluetoothAdapter.cancelDiscovery();
try
{
    btSocket.connect(); <-- FAILED HERE
}
catch (IOException e) 
{
    e.printStackTrace(); //java.io.IOException: Service discovery failed
}
4

0 回答 0