Skip to content Skip to sidebar Skip to footer

Getbluetoothservice() Called With No Bluetoothmanagercallback For Android Nexus 5

I am going to implemenet the module for sending commands from my Android smartphone to HC-06 via BLuetooth. WHen it comes to the execution , it show s the following exception and f

Solution 1:

since android 4.2 , bluetooth stack changed, so i guess you are testing on android>=4.2 .

your problem is here tmp = device.createRfcommSocketToServiceRecord(MY_UUID); . this socket creation method is not compatible starting with 4.2 , so you will need to use the fallback one after it fails : tmp =(BluetoothSocket) device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(device,1);

Don't worry about called with no BluetoothManagerCallback being thrown, it doesn't matter.

So if you do it like this, it will work:

try {
            socket = device.createRfcommSocketToServiceRecord(SERIAL_UUID);
        } catch (Exception e) {Log.e("","Error creating socket");}

        try {
            socket.connect();
            Log.e("","Connected");
        } catch (IOException e) {
            Log.e("",e.getMessage());
            try {
                Log.e("","trying fallback...");

                socket =(BluetoothSocket) device.getClass().getMethod("createRfcommSocket", newClass[] {int.class}).invoke(device,1);
                socket.connect();

                Log.e("","Connected");
            }

also, i answered here more detailed, about a similar problem.

Post a Comment for "Getbluetoothservice() Called With No Bluetoothmanagercallback For Android Nexus 5"