Thanks for the comment. I actually wanted to send the bytes to an android phone where it actually recieves the byte and undergoes a process to retrieve the jpg image from bytes. The android code to receive the bytes and to convert back to jpg is given below
//This thread runs during a connection with a remote device. It handles all incoming and outgoing transmissions.
private class ConnectedThread extends Thread {
private final BluetoothSocket mmBTSocket;
private final InputStream mmBTInStream;
private final OutputStream mmBTOutStream;
public ConnectedThread(BluetoothSocket socket) {
Log.d(BTTAG, "create ConnectedThread");
mmBTSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
// Get the BluetoothSocket input and output streams
try {
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
} catch (IOException e) {
Log.e(BTTAG, "temp sockets not created", e);
}
mmBTInStream = tmpIn;
mmBTOutStream = tmpOut;
}
public void run() {
Log.i(BTTAG, "BEGIN mBTConnectedThread");
byte[] inBTBuffer = new byte[1024];
boolean BTFileEndOne = false;
// byte[] mBTimageBuffer = new byte[15360]; // 15KB reserved
int bytes;
// long start= System.currentTimeMillis() ;
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmBTInStream.read(inBTBuffer);
for (int i = 0; i < bytes; i++) {
mBTimageBuffer[mBTfileIndex] = inBTBuffer[i];
mBTfileIndex++;
// start = System.currentTimeMillis();
// Log.i(BTTAG, bytes+"="+String.format("%02X",
// inBTBuffer[i]));
if (i > 0) {
if (inBTBuffer[i] == (byte) 0xD9) {
// BTFileEndOne = true;
// Log.i(BTTAG, "BTFileEndOne = true");
if (inBTBuffer[i - 1] == (byte) 0xFF) {
if (SaveImagetoSD() == true) {
mBTHandler
.obtainMessage(
MainCameraActionActivity.BT_MESSAGE_READ,
bytes, -1, inBTBuffer)
.sendToTarget();
}
// Log.i(BTTAG, "FileEndTwo = true");
}
}
}
}
// if(System.currentTimeMillis() - start > 1000)
// SaveImagetoSD();
// Log.i(BTTAG, "mBTfileIndex="+mBTfileIndex);
// nTotalReceiveBytes = nTotalReceiveBytes + bytes;
// SaveImagetoSD(inBTBuffer, bytes);
// if(nTotalReceiveBytes >= 1024)
// {
// Send the obtained bytes to the UI Activity
// mHandler.obtainMessage(MainCameraActionActivity.BT_MESSAGE_READ, bytes, -1,
// inBTBuffer).sendToTarget();
// }
} catch (IOException e) {
Log.e(BTTAG, "Disconnected", e);
connectionLost();
break;
}
}
}
/**
* Write to the connected OutStream.
*
* @param buffer
* The bytes to write
*/
public void write(byte[] outBuffer) {
try {
mmBTOutStream.write(outBuffer);
// Share the sent message back to the UI Activity
mBTHandler.obtainMessage(
MainCameraActionActivity.BT_MESSAGE_WRITE, -1, -1,
outBuffer).sendToTarget();
} catch (IOException e) {
Log.e(BTTAG, "Exception during write", e);
}
}
public void cancel() {
try {
if (DIVICE)
Log.d(BTTAG, "ConnectThread : mmBTSocket.close() ...");
mmBTSocket.close();
if (DIVICE)
Log.d(BTTAG, "ConnectThread : mmBTSocket.close() ...");
} catch (IOException e) {
Log.e(BTTAG, "close() of connect socket failed", e);
}
}
}
public boolean checkSDCard() {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
public boolean SaveImagetoSD() {
Log.i(BTTAG, "SaveImagetoSD ");
String extStorage = Environment.getExternalStorageDirectory()
.toString();
File file = new File(extStorage, "motoduino.jpg");
if (checkSDCard() == false)
return false;
try {
mBTImageOutStream = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mBTImageOutStream.write(mBTimageBuffer, 0, mBTfileIndex);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i(BTTAG, "Save file size = " + mBTfileIndex);
return true;
}
public static String hexadecimal(String input, String charsetName)
throws UnsupportedEncodingException {
if (input == null)
throw new NullPointerException();
return asHex(input.getBytes(charsetName));
}
private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
public static String asHex(byte[] buf) {
char[] chars = new char[2 * buf.length];
for (int i = 0; i < buf.length; ++i) {
chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
}
return new String(chars);
}
}