手上有个蓝牙设备,想用手机接收设备上发送出来的数据,数据是十六进制的。网上看到可以用bluetoothSocket虚拟串口实现,但没有类似的例子,哪位仁兄能帮下忙指点一下啊

解决方案 »

  1.   


    public class BluetoothOppRfcommTransport implements ObexTransport {    private final BluetoothSocket mSocket;    public BluetoothOppRfcommTransport(BluetoothSocket socket) {
            super();
            this.mSocket = socket;
        }    public void close() throws IOException {
            mSocket.close();
        }    public DataInputStream openDataInputStream() throws IOException {
            return new DataInputStream(openInputStream());
        }    public DataOutputStream openDataOutputStream() throws IOException {
            return new DataOutputStream(openOutputStream());
        }    public InputStream openInputStream() throws IOException {
            return mSocket.getInputStream();
        }    public OutputStream openOutputStream() throws IOException {
            return mSocket.getOutputStream();
        }    public void connect() throws IOException {
        }    public void create() throws IOException {
        }    public void disconnect() throws IOException {
        }    public void listen() throws IOException {
        }    public boolean isConnected() throws IOException {
            //return mSocket.isConnected();
            // TODO: add implementation
            return true;
        }    public String getRemoteAddress() {
            if (mSocket == null)
                return null;
            return mSocket.getRemoteDevice().getAddress();
        }}