Sending file to Android from Bluetooth Mate Gold
<p>I am trying to use (a modified version of) Android Bluetooth chat example to receive an image file sent from Bluetooth Mate Gold module (http://www.sparkfun.com/products/9358)</p>

<p>I could establish the connection. I can sent some small commands (both ways). But when I tried to send a file (4kb) from my bluetooth module to phone, some bytes are corrupted. </p>

<p>From bluetooth module side, I send the token "-str" to indicate the start of a file and "-end" to indicate the end of file. So basically, I write bytes between "-str" and "-end" into a file...</p>

<p>Here is the part of the android example that I changed....</p>

<pre><code>            case MESSAGE_READ:
            byte[] readBuf = (byte[]) msg.obj;
            // construct a string from the valid bytes in the buffer
            String readMessage = new String(readBuf, 0, msg.arg1);

            if(readMessage.equals("-end")){ //end of file received
                Toast.makeText(getApplicationContext(), "End of file.", Toast.LENGTH_SHORT).show();
                if (flag=false){ //file start has not received
                    Toast.makeText(getApplicationContext(), "Error in receiving data.", Toast.LENGTH_SHORT).show();
                }
                else{
                    if (end_received==false){
                        mConversationArrayAdapter.add(readMessage);
                            flag = false; //make "-str" receive flag false (get ready for the next file)
                        try {
                        bw.flush();
                        bw.close();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        i=i+1;                  
                        Toast.makeText(getApplicationContext(), "Image data received.", Toast.LENGTH_SHORT).show();
                        end_received=true;  
                    }
               }
            }

            if(flag==true){ //if we have receive "-str"
                try {
                    imagedata = imagedata.concat(new String(readBuf,0,msg.arg1));
                    bw.write(readBuf, 0, msg.arg1);
                     }

        } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
        }
            }


            if(readMessage.equals("-str")){ //make flag=true when "-str" received, start a new filename 
                mConversationArrayAdapter.add(readMessage);
                flag = true; 
                end_received=false;
            String FileName = "ring" + Integer.toString(i) + ".jpg";
                localFile1 = new File(path, FileName);
                try {
                localFile1.createNewFile();
                 bw = new BufferedOutputStream(new FileOutputStream(localFile1));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
</code></pre>

<h1>                }</h1>

<p>It has been a week+ does anybody have an answer to this question?</p>
