标签:io os ar java sp 数据 on art 问题
============问题描述============
public void Start() { LogHelper.Write("开始连接bluetooth device"); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice device = bluetoothAdapter.getRemoteDevice(this.deviceAddress); UUID deviceUUId=UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); try { this.clientSocket=device.createRfcommSocketToServiceRecord(deviceUUId); this.clientSocket.connect(); LogHelper.Write("连接成功"); this.connectedThread=new ConnectedThread(clientSocket); byte[] buffer=new byte[]{0x3a,0x50,0x00,(byte) 0x8a}; connectedThread.write(buffer); LogHelper.Write("已写入开始命令"); connectedThread.run(); LogHelper.Write("已经运行过子线程"); } catch(IOException e) { LogHelper.Write(e.getMessage()); } }
private class ConnectedThread extends Thread { private final BluetoothSocket mmSocket; private final InputStream mmInStream; private final OutputStream mmOutStream; public ConnectedThread(BluetoothSocket socket) { mmSocket = socket; InputStream tmpIn = null; OutputStream tmpOut = null; try { tmpIn = socket.getInputStream(); tmpOut = socket.getOutputStream(); } catch (IOException e) { LogHelper.Write(e.getMessage()); } mmInStream = tmpIn; mmOutStream = tmpOut; } public void run() { byte[] buffer = new byte[1024]; int bytes; while (true) { try { bytes = mmInStream.read(buffer); //处理数据 writeToBuffer(buffer,seBuffer,readPointer,writePointer,bytes); readBuffer(seBuffer,readPointer,writePointer); } catch (IOException e) { LogHelper.Write(e.getMessage()); break; } } } //往蓝牙通讯管道中写入数据 public void write(byte[] buffer) { try { mmOutStream.write(buffer); } catch (IOException e) {} } }
============解决方案1============
connectedThread.run();
connectedThread.start();
标签:io os ar java sp 数据 on art 问题
原文地址:http://www.cnblogs.com/meizhenfen42/p/4033883.html