android蓝牙“服务发现失败”

时间:2012-12-16 12:36:03

标签: android bluetooth

虽然已经有很多关于这个主题的文章,但我仍然无法找到解决我特定问题的方法:

我正在尝试将Sasmsung 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
}

0 个答案:

没有答案