0

I am developing an app to control a custom device. This custom device has a dual mode bluetooth and working in dual mode function for accepting Android and iOS connections.

With Android I need use classic connection. I made some tests with several smartphones and tablets. However, with some tablets models I am have problem to connect.

I have a tablet with MT6572 SOC from MediaTek and it has 4.4.2 android. I also have a SAMSUNG Galaxy Tab E with SC8830 SOC from Spreadtrum and it has 4.4.4 android. Both tablets has API level 19.

I get the adapter this way :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
       if (mBluetoothManager == null) {
            mBluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
            if (mBluetoothManager == null) {
                return false;
            }
        }
        mBluetoothAdapter = mBluetoothManager.getAdapter();
    }

And to connect I code this way:

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);

BluetoothSocket socket = device.createRfcommSocketToServiceRecord(myUUID); 
socket.connect()

The socket is created successfully, but when I try to connect I receive the following error/message:

java.io.IOException: read failed, socket might closed or timeout, read ret: -1

When I observe the log from my custom device with dual mode bluetooth I see events from a Low Energy connection. It seem that Android is not respecting my attempt of creating socket and classic bluetooth connection.

Is behavior normal this? can be a bug in android?

Thanks

Arubu
  • 445
  • 4
  • 19

1 Answers1

0
  1. Check if device is discoverable using mBluetoothAdapter.startDiscovery(),javadoc

  2. Check if you paired a custom device with Android device. You also can do this manually. How to pair bluetooth devices programmatically?

  3. Do the connect via createRfcommSocketToServiceRecord

This approach works for me in many cases.

Community
  • 1
  • 1
Hollywood
  • 620
  • 6
  • 5
  • Thanks for answer. I am using this approach too. The samsung tablet worked like a charm, my tests were wrong. But the MT6572 SOC did not work, I am thinking that there is a bug inside of the bluetooth stack. – Arubu Feb 26 '16 at 16:19