bluetooth error service discovery failed in android
I have get below UUID from "Service discovery failed" from Android Bluetooth Insecure Rfcomm private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); Using this UUID I am able to connect other handsets(Bada,Blackberry) except android. below is code that i have get from android sample /
**
* This thread runs while attempting to make an outgoing connection
* with a device. It runs straight through; the connection either
* succeeds or fails.
*/
private class ConnectThread extends Thread
{
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
BluetoothSocket tmp = null;
public ConnectThread(BluetoothDevice device)
{
mmDevice = device;
// Get a BluetoothSocket for a connection with the
// given BluetoothDevice
try
{
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
Log.d(TAG, "tmp = "+tmp.toString());
}
catch (IOException e)
{
Log.e(TAG, "create() failed", e);
}
mmSocket = tmp;
}
public void run()
{
Log.i(TAG, "BEGIN mConnectThread");
setName("ConnectThread");
// Always cancel discovery because it will slow down a connection
mAdapter.cancelDiscovery();
// Make a connection to the BluetoothSocket
try
{
// This is a blocking call and will only return on a
// successful connection or an exception
Log.d(TAG, " before connecting mmsocket.connect()");
mmSocket.connect();
Log.d(TAG, " after connecting mmsocket.connect()");
}
catch (IOException e)
{
Log.d(TAG, " before connectionFailed()");
connectionFailed();
Log.d(TAG, " after connectionFailed()");
Log.d(TAG, "after connectiofailed exception is: "+ e.toString());
// Close the socket
try
{
mmSocket.close();
}
catch (IOException e2)
{
Log.d(TAG, "unable to close() socket during connection failure: "+ e2.toString());
}
// // Start the service over to restart listening mode
// BluetoothChatService.this.start();
return;
}
// Reset the ConnectThread because we're done
synchronized (BluetoothService.this)
{
mConnectThread = null;
}
Log.d(TAG, " before connected mmsocket and mmdevice");
// Start the connected thread
connected(mmSocket, mmDevice);
Log.d(TAG, "after connected mmsocket and mmdevice");
}
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) {
Log.e(TAG, "close() of connect socket failed", e);
}
}
}
I am getting error service discovery failed. I want to pair 2 android handsets Please help !!!
链接地址: http://www.djcxy.com/p/82012.html上一篇: 服务发现失败
下一篇: Android中的蓝牙错误服务发现失败