Application/src/main/java/com/example/android/bluetoothchat/BluetoothChatFragment.java
private void sendMessage(String message) {
        // Check that we're actually connected before trying anything
        if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) {
            Toast.makeText(getActivity(), R.string.not_connected, Toast.LENGTH_SHORT).show();
            return;
        }

        // Check that there's actually something to send
        if (message.length() > 0) {
            // Get the message bytes and tell the BluetoothChatService to write

            System.out.println(message);
            message = interpretor.createSendString("bob","all",message);
            System.out.println(message);

            byte[] send = message.getBytes();

            byte[] p1 = new byte[1024];
            byte[] p2 = new byte[1024];

            System.arraycopy(send,0,p1,0,1024);
            System.arraycopy(send,1024,p2,0,send.length - 1024);

            // message encrypted here
            mChatService.write(p1);

            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            mChatService.write(p2);

            // Reset out string buffer to zero and clear the edit text field
            mOutStringBuffer.setLength(0);
            mOutEditText.setText(mOutStringBuffer);
        }
    }
/**
     * Sends a message.
     *
     * @param message A string of text to send.
     */
Sends a message.
@param message A string of text to send.
Sends a message . @param message A string of text to send .
private void sendMessage(String message) {
        if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) {
            Toast.makeText(getActivity(), R.string.not_connected, Toast.LENGTH_SHORT).show();
            return;
        }
        if (message.length() > 0) {
            System.out.println(message);
            message = interpretor.createSendString("bob","all",message);
            System.out.println(message);
            byte[] send = message.getBytes();
            byte[] p1 = new byte[1024];
            byte[] p2 = new byte[1024];
            System.arraycopy(send,0,p1,0,1024);
            System.arraycopy(send,1024,p2,0,send.length - 1024);
            mChatService.write(p1);
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            mChatService.write(p2);
            mOutStringBuffer.setLength(0);
            mOutEditText.setText(mOutStringBuffer);
        }
    }
private void sendMessage ( String message ) { if ( mChatService . getState ( ) != BluetoothChatService . STATE_CONNECTED ) { Toast . makeText ( getActivity ( ) , R . string . not_connected , Toast . LENGTH_SHORT ) . show ( ) ; return ; } if ( message . length ( ) > 0 ) { System . out . println ( message ) ; message = interpretor . createSendString ( "bob" , "all" , message ) ; System . out . println ( message ) ; byte [ ] send = message . getBytes ( ) ; byte [ ] p1 = new byte [ 1024 ] ; byte [ ] p2 = new byte [ 1024 ] ; System . arraycopy ( send , 0 , p1 , 0 , 1024 ) ; System . arraycopy ( send , 1024 , p2 , 0 , send . length - 1024 ) ; mChatService . write ( p1 ) ; try { Thread . sleep ( 2000 ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } mChatService . write ( p2 ) ; mOutStringBuffer . setLength ( 0 ) ; mOutEditText . setText ( mOutStringBuffer ) ; } }
Sends a message.
Sends a message .
// Check that we're actually connected before trying anything // Check that there's actually something to send // Get the message bytes and tell the BluetoothChatService to write // message encrypted here // Reset out string buffer to zero and clear the edit text field