akexorcist / BluetoothSPPLibrary

[UNMAINTAINED][Android] Bluetooth Serial Port Profile which comfortable to developer application to communication with microcontroller via bluetooth
Apache License 2.0
1.71k stars 571 forks source link

Send() os not working #80

Open vidyajejurkar opened 7 years ago

vidyajejurkar commented 7 years ago

Need help.I am not able to send data to device.

swallowsonny commented 7 years ago

public void run() { byte[] buffer; ArrayList arr_byte = new ArrayList();

        // Keep listening to the InputStream while connected
        while (true) {
            try {
                int data = mmInStream.read();
                if (data == CheckCode.FLAG_BEGIN) {     //_fix this_ 
                    arr_byte.clear();
                    arr_byte.add(data);
                } else if (data == CheckCode.FLAG_END) {   //_fix this_
                    arr_byte.add(data);
                    buffer = new byte[arr_byte.size()];
                    for (int i = 0; i < arr_byte.size(); i++) {
                        buffer[i] = arr_byte.get(i).byteValue();
                    }
                    mHandler.obtainMessage(BluetoothState.MESSAGE_READ, buffer.length, -1, buffer).sendToTarget();
                    arr_byte.clear();
                } else {
                    arr_byte.add(data);
                }
            } catch (IOException e) {
                connectionLost();
                break;
            }
        }
    }
vidyajejurkar commented 7 years ago

Still not working :-(

public void run() { byte[] buffer; ArrayList arr_byte = new ArrayList();

        // 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;
            }
        }
    }
KingOfSu commented 7 years ago

i have the same issue, but i use sample can send data, i put the code in my project is not working.

KingOfSu commented 7 years ago

i solve it but i dont know why

DragonSoul1 commented 7 years ago

All is working except send functoin. API 25