akexorcist / BluetoothSPPLibrary

[UNMAINTAINED][Android] Bluetooth Serial Port Profile which comfortable to developer application to communication with microcontroller via bluetooth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AcceptThread crash

ryazmin opened this issue · comments

commented

AcceptThread will crash if listenUsingRfcommWithServiceRecord method throws exception.
In this case mmServerSocket will be null,
and crash will be at AcceptThread.run line socket = mmServerSocket.accept();

Also need to check for null in AcceptThread .cancel method or catch any exception.

Thanks!

in class app.akexorcist.bluetotohspp.library.BluetoothSPP line 371 when arr_name.size()==0 a arr ArrayIndexOutOfBoundsException occured

I noticed this same problem in case if I will switch off the BT in my phone during connection.

commented

I set the Listener, but received nothing. Follow is the codes:
bt.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
@OverRide
public void onDataReceived(byte[] data, String message) {
System.out.println("APP:received-" /+ message/);
}
});
Need your help, thanks

i have the same problem as r00kie0, setting the bluetooth data listener, but i can not receive
anything, i need your help. thanks.

onDataReceived(byte[] data, String message)
NOT working here.. same problem.. plz give solution

commented

The function of onDataReceived not work, plz give solution. tks~

Hello Guys,

To receive messages correctly the text should have a 0x0A and 0x0D at the end. Like you can see in this code:

// Keep listening to the InputStream while connected
            while (true) {
                try {
                    int data = mmInStream.read();
                    if(data == 0x0A) {

                    } else if(data == 0x0D) {
                        buffer = new byte[arr_byte.size()];
                        for(int i = 0 ; i < arr_byte.size() ; i++) {
                            buffer[i] = arr_byte.get(i).byteValue();
                        }
                        // Send the obtained bytes to the UI Activity
                        mHandler.obtainMessage(BluetoothState.MESSAGE_READ
                                , buffer.length, -1, buffer).sendToTarget();
                        arr_byte = new ArrayList<Integer>();
                    } else {
                        arr_byte.add(data);
                    }
                } catch (IOException e) {
                    connectionLost();
                    // Start the service over to restart listening mode
                    BluetoothService.this.start(BluetoothService.this.isAndroid);
                    break;
                }
            }

What about that "AcceptThread" null reference mentioned in the very first message?
Do you plan to fix it?
This causes great inconvenience to our company, so if you have stalled the project, plz let me know to use another package

commented

jtoros13 did you find a solution? I'm getting the same problem and I don't have access to the phone in question.

Nope, no "out of the box" solution found.
I downloaded the code in my project as a different package, and after adding it as external reference, I changed the code itself.

Hope this helps
jtoros13

@akexorcist
First of all, thank you for your work in this project.

Sorry for my english, I'm from Argentina. As mentioned in some comments, I need to know if it is going to solve the "AcceptThread" bug, because I have a project to finish and one of the things that slow me down is this bug.

sorry i got this problem how to slove
"Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model."