Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

java - Android Bluetooth Connection - Service Discovery Failed

I'm trying to create a basic bluetooth application, for testing the device.

I got the code from developer.android. Here is the link : http://developer.android.com/guide/topics/connectivity/bluetooth.html#ConnectingDevices

Here is run part of my thread code:

     public void run() {

        mBluetoothAdapter.cancelDiscovery();
        Log.i(TAG, "Discovery Cancel!"); 

        try {
            Log.i(TAG, "Connection Started");
            mmSocket.connect();
            Log.i(TAG, "Connection Ended");
        } catch (IOException e) {
            try {
                Log.e(TAG, "Connection Failed", e);
                mmSocket.close();
            } catch (IOException e2) {
                Log.e(TAG, "Connection Close Failed", e2);
            }
            return;
        }

Whatever I have tried mmSocket.connect(); never works. Always throws an IOException and I get that log from my logcat:

java.io.IOException: Service discovery failed
at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:403)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:213)

I've looked at these articles, and tried the written things, none of them has solved my problem.

Android Bluetooth: Service Discovery Failed, connection to Desktop/Laptop

Service discovery failed exception using Bluetooth on Android

Bluetooth connection on Android ICS not possible

Android Bluetooth java.io.IOException: Connection refused?

Btw I'm working on android ics 4.0.4.

I know that is not device problem, cause I've tried this app on different devices.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't know and I still don't understand the UUID stuff but the problem was the UUID. I'm using the UUID which I got from the kernel logs and it is 00001105-0000-1000-8000-00805F9B34FB.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...