3

I am trying with blue-tooth chat example for api-10, in my micromax pfhone.

When I scanning for devices it showing the list for both secure and non secure. But When I try to connect it showing unable to connect.

And UUIDs are:

private static final UUID MY_UUID_SECURE = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
private static final UUID MY_UUID_INSECURE =UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66");

I tried this post, Service discovery failed exception using Bluetooth on Android , but no change.

Any ideas?

This is my code for connecting to a blue-tooth device while pairing. I got this code from android api-10 samples:

        try {
            if (secure) {
                tmp = device.createRfcommSocketToServiceRecord(
                        MY_UUID_SECURE);
            } else {
                tmp = device.createInsecureRfcommSocketToServiceRecord(
                        MY_UUID_INSECURE);
            }
        } catch (IOException e) {
            Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
        }
        mmSocket = tmp;
    }

    public void run() {
        Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType);
        setName("ConnectThread" + mSocketType);

        // 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
            mmSocket.connect();
        } catch (IOException e) {
            // Close the socket
            try {
                mmSocket.close();
            } catch (IOException e2) {
                Log.e(TAG, "unable to close() " + mSocketType +
                        " socket during connection failure", e2);
            }
            connectionFailed();
            return;
        }
Community
  • 1
  • 1
Haris
  • 13,645
  • 12
  • 90
  • 121
  • Hi @Haris Do you got any solutions ? I'm also stuck on same area. Its working with samsung galaxy Y but not on micromax A52 – Aswin Anand Oct 09 '12 at 11:56
  • I am also using Micromax A52. I didn't test on any other device. I think you need to run the same chat application on the other device.I got this from https://groups.google.com/forum/?fromgroups=#!searchin/android-developers/bluetooth$20chat$20not$20working/android-developers/fNm0vvzPlg8/fCtqyANwb9gJ – Haris Oct 10 '12 at 04:37
  • You can search android Google groups "Bleutooth chat Api 10 not working" I posted the same issue there.. – Haris Oct 10 '12 at 04:57
  • Hi aswin have you got any solution...Is it working when the other device running the same chat application. I didn't test that because right now I have only one android device... – Haris Oct 11 '12 at 11:36

1 Answers1

0

An obvious question, but still:

Did you register the 2 Bluetooth permissions in the Android manifest file?

Radu
  • 2,076
  • 2
  • 20
  • 40
  • Yes I already registered....... Actually by referring some post I realized that at the same time the other device should run the blue-tooth chat application....then only it is possible to pair the device....But for my application I am reusing the code for bluetooth communication for some other purpose....And in which I need to pair my device with other one which discoverable mode is ON at that time.....Any idea.... And thanks for your reply – Haris Sep 07 '12 at 11:08
  • Do you want to make another device discoverable? There is a timeout for this Android - because it consumes the battery. Read this: http://developer.android.com/guide/topics/connectivity/bluetooth.html#EnablingDiscoverability. Maximum discoverable time is 1 hour. Don't forget to vote up! – Radu Sep 07 '12 at 11:22
  • Yes I am setting another device discoverable manually by bluetooth setting...then only I start my bluetooth chat application....It's searching and listing the devices but when I try to connect to the listed device it's showing not able to connect...But I need to pair my device with the other after searching insted of connecting........Thanks..... – Haris Sep 08 '12 at 05:00