0

At first, I was able to easily connect/disconnect and receive from my bluetooth remote device with my android phone running ICS (4.0.4).
Recently, somehow, my app doesn't work anymore.
There's no error, just no data is sent or received, because there's no socket created in connection.
My first guess is my hardware, but it's not.
I tried my basic bluetooth connection apps and they won't work neither.
Here is the logcat :

01-05 22:04:42.576: D/bluetooth2(5316): ...Connecting...
01-05 22:04:42.576: I/BluetoothSocket_MTK(5316): [JSR82] connect: do SDP
01-05 22:04:42.577: I/BluetoothSocket_MTK(5316): [JSR82] close
01-05 22:04:42.577: I/BluetoothSocket_MTK(5316): [JSR82] readLock got.
01-05 22:04:42.577: I/BluetoothSocket_MTK(5316): [JSR82] Start to aquire writeLock.
01-05 22:04:42.577: I/BluetoothSocket_MTK(5316): [JSR82] writeLock got.
01-05 22:04:42.578: D/bluetooth2(5316): ...Create Socket...
01-05 22:04:42.584: D/dalvikvm(5316): threadid=14: interp stack at 0x4d1b5000
01-05 22:04:42.587: D/dalvikvm(5316): threadid=14 (Thread-371): calling run()
01-05 22:04:42.594: D/Buffer read(5316): ...[B@417c0930
01-05 22:04:42.594: D/dalvikvm(5316): threadid=14: exiting
01-05 22:04:42.594: D/dalvikvm(5316): threadid=14: bye!
01-05 22:04:42.594: D/dalvikvm(5316): threadid=0: freeing
01-05 22:04:43.135: I/BluetoothSocket_MTK(5316): [JSR82] SdpHelper::onRfcommChannelFound: channel=-1
01-05 22:04:43.135: I/BluetoothSocket_MTK(5316): [JSR82] close
01-05 22:04:43.135: I/BluetoothSocket_MTK(5316): [JSR82] readLock got.
01-05 22:04:43.135: D/bluetooth2(5316): ...Create Socket...
01-05 22:04:43.138: D/dalvikvm(5316): threadid=14: interp stack at 0x4d1b5000
01-05 22:04:43.138: D/dalvikvm(5316): threadid=14 (Thread-372): calling run()
01-05 22:04:43.138: D/Buffer read(5316): ...[B@417c0ec0
01-05 22:04:43.138: D/dalvikvm(5316): threadid=14: exiting
01-05 22:04:43.138: D/dalvikvm(5316): threadid=14: bye!
01-05 22:04:43.138: D/dalvikvm(5316): threadid=0: freeing
01-05 22:04:43.149: I/BluetoothSocket_MTK(5316): [JSR82] close
01-05 22:04:43.149: I/BluetoothSocket_MTK(5316): [JSR82] readLock got.
01-05 22:04:46.149: I/BluetoothSocket_MTK(5316): [JSR82] Bluetooth Socket Constructor
01-05 22:04:46.150: I/BluetoothSocket_MTK(5316): [JSR82] type=1 fd=-1 auth=false encrypt=false port=-1

I saw several people encounter the same problem with a bluetooth connection on ICS.
Also I tried to fix it using this, but it doesn't work either.
It says: Could not create Insecure RFComm Connection.

Here is the snippet:

private BluetoothAdapter btAdapter = null;
      private BluetoothSocket btSocket = null;
      private StringBuilder sb = new StringBuilder();

      private ConnectedThread mConnectedThread;

      // SPP UUID service
      private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

      // MAC-address of Bluetooth module (you must edit this line)
      private static String address = "20:13:06:24:05:60";

OnCreate

btAdapter = BluetoothAdapter.getDefaultAdapter();

The bluetooth connection

private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {
          if(Build.VERSION.SDK_INT >= 10){
              try {
                  final Method  m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class });
                  return (BluetoothSocket) m.invoke(device, MY_UUID);
              } catch (Exception e) {
                  Log.e(TAG, "Could not create Insecure RFComm Connection",e);
              }
          }
          return  device.createRfcommSocketToServiceRecord(MY_UUID);
      }

      public void bluetoothDisconnect(){
          try     {
              btSocket.close();
            } catch (IOException e2) {
              errorExit("Fatal Error", "In onPause() and failed to close socket." + e2.getMessage() + ".");
            }

      }

      public void bluetoothConnect(){
        // Set up a pointer to the remote node using it's address.
            BluetoothDevice device = btAdapter.getRemoteDevice(address);

            // Two things are needed to make a connection:
            //   A MAC address, which we got above.
            //   A Service ID or UUID.  In this case we are using the
            //     UUID for SPP.

            try {
                btSocket = createBluetoothSocket(device);
            } catch (IOException e) {
                errorExit("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + ".");
            }

            /*try {
              btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
            } catch (IOException e) {
              errorExit("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + ".");
            }*/

            // Discovery is resource intensive.  Make sure it isn't going on
            // when you attempt to connect and pass your message.
            btAdapter.cancelDiscovery();

            // Establish the connection.  This will block until it connects.
            Log.d(TAG, "...Connecting...");
            try {
              btSocket.connect();
              Log.d(TAG, "....Connection ok...");
            } catch (IOException e) {
              try {
                btSocket.close();
              } catch (IOException e2) {
                errorExit("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + ".");
              }
            }

            // Create a data stream so we can talk to server.
            Log.d(TAG, "...Create Socket...");

            mConnectedThread = new ConnectedThread(btSocket);
            mConnectedThread.start();


      }

Is this issue fixable? Especially for this android version?
Thanks

Community
  • 1
  • 1
Rijdzuan Sampoerna
  • 380
  • 1
  • 6
  • 18
  • I am also facing this problem.Did you find a solution to it ? – Basher51 Mar 13 '14 at 04:30
  • Not yet for ICS, try with another version of Android. Works fine to me. – Rijdzuan Sampoerna Mar 13 '14 at 06:08
  • Ok so are you saying that when you switched to another android version(for the same hardware device)the bluetooth connection problem didn't arise ? – Basher51 Mar 13 '14 at 06:30
  • Yup that's what happened to me, i ran my system with gingerbread now. It just works. – Rijdzuan Sampoerna Mar 13 '14 at 06:33
  • 1
    OK..I am stuck with this bluetooth prob for last couple of days.It works perfectly on samsung s2 but fails to work on iball 3G 7271.The latter apparently runs on MTK family of processor.I read a post -"http://redacacia.me/2012/07/17/overcoming-android-bluetooth-blues-with-reflection-method/" according to which MTK family devices have some bluetooth connectivity issues.Now I am in a fix,is it a s/w or a h/w issue .. – Basher51 Mar 13 '14 at 06:40
  • hey i do have same problem that saying the error from MTK. My first guess that its a hardware issue from my phone(Lenovo A390), but then i can't found the good source to support my diagnose. Just change the phone with different android version, like i did. And you are good to go – Rijdzuan Sampoerna Mar 13 '14 at 09:26
  • Hmmm, I contacted the customer service of iball and they said that I cant downgrade the OS.This tab comes with 4.1.2 and cant be upgraded as per them,crap :/ – Basher51 Mar 13 '14 at 10:30

0 Answers0