File tree 1 file changed +9
-3
lines changed
lmbluetoothsdk/src/main/java/co/lujun/lmbluetoothsdk/service
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 24
24
import java .io .IOException ;
25
25
import java .io .InputStream ;
26
26
import java .io .OutputStream ;
27
+ import java .util .Arrays ;
27
28
import java .util .UUID ;
28
29
29
30
import co .lujun .lmbluetoothsdk .base .BaseListener ;
@@ -355,9 +356,14 @@ public void run() {
355
356
int bytes ;
356
357
while (true ) {
357
358
try {
358
- bytes = mmInStream .read (buffer );
359
- if (mBluetoothListener != null ){
360
- ((BluetoothListener )mBluetoothListener ).onReadData (mmSocket .getRemoteDevice (), buffer );
359
+ if (mmInStream .available ()>0 ) {
360
+ bytes = mmInStream .read (buffer );
361
+ if (bytes >0 ) {
362
+ byte [] data = Arrays .copyOf (buffer ,bytes );
363
+ if (mBluetoothListener != null ) {
364
+ ((BluetoothListener ) mBluetoothListener ).onReadData (mmSocket .getRemoteDevice (), data );
365
+ }
366
+ }
361
367
}
362
368
} catch (IOException e ) {
363
369
setState (co .lujun .lmbluetoothsdk .base .State .STATE_DISCONNECTED );
You can’t perform that action at this time.
0 commit comments