Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - Reading corrupted bluetooth data in Android

Reading corrupted bluetooth data in Android

Put your problem here if it does not fit any of the other categories.

Reading corrupted bluetooth data in Android

Postby Christo » Tue Sep 20, 2011 8:46 am

Hi, I used the bluetoothChat program from Android Development website to connect with a bluetooth device. I sent very little data to the device, but want to recieve a lot of data. Everything works great, but about half the data that I recieve are corrupted. Half the characters I get are funny questionmarks. I debuged the program and saw that the question marks are negative ascii digits. So do I read the data wrong or what is it?

This is the code that I use to read the data:

Code: Select all
public void run() {
            byte[] buffer = new byte[1024];
            int bytes;

            // Keep listening to the InputStream while connected
            while (true) {
                try {
                    // Read from the InputStream
                    bytes = mmInStream.read(buffer);
                     
                    // Send the obtained bytes to the UI Activity
                    mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer).sendToTarget();
                   
                } catch (IOException e) {
                    Log.e(TAG, "disconnected", e);
                    connectionLost();
                    break;
                }
            }


This is the code that I use to display the data

Code: Select all
    // The Handler that gets information back from the BluetoothChatService
    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
           Log.e(TAG, "# mHandler   handleMessage");
           Log.i(TAG, "DEBUG (mHandler: " + msg + " * " + msg.what);
            switch (msg.what) {
            case MESSAGE_READ:
                byte[] readBuf = (byte[]) msg.obj;
               
                Log.e(TAG, "readBuf:" + readBuf);
               
                // construct a string from the valid bytes in the buffer
                String str = EncodingUtils.getAsciiString(readBuf, 0, msg.arg1);
                mConversationArrayAdapter.add(mConnectedDeviceName+":  " + str);
                break;
            }
        }
    };


Thanks
Christo
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Sep 20, 2011 8:13 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests