Code example for BluetoothSocket

Methods: connect, getInputStream, getOutputStream

0
     
    void openBT() throws IOException 
    { 
        UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID
        mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);        
        mmSocket.connect();
        mmOutputStream = mmSocket.getOutputStream();
        mmInputStream = mmSocket.getInputStream();
         
         
        connected = true;
    } 
     
    void sendData(String msg) throws IOException
    { 
        msg += "\n";
        mmOutputStream.write(msg.getBytes());
        //myLabel.setText("Data Sent"); 
        Log.d ("RGB", msg);
    }