I want to receive a jpeg image in android from a hardware via Bluetooth . I want to read the inputstream and show the actual data from byte array. my actual data looks like:
ff d8 ff e1 63 70 45 78 69 66 00 00 49 49 2a 00
08 00 00 00 0b 00 0f 01 02 00 06 00 00 00 92 00
.........................ff d9
I used this code:
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();
beginListenForData();
//ConnectedThread(mmSocket);
myLabel.setText("Bluetooth Opened");
}
void beginListenForData()
{
final Handler handler = new Handler();
final byte delimiter = 10; //This is the ASCII code for a newline character
stopWorker = false;
readBufferPosition = 0;
readBuffer = new byte[1024];
workerThread = new Thread(new Runnable()
{
public void run()
{
while(!Thread.currentThread().isInterrupted() && !stopWorker)
{
try
{
int bytesAvailable = mmInputStream.available();
if(bytesAvailable > 0)
{
final byte[] packetBytes = new byte[bytesAvailable];
mmInputStream.read(packetBytes);
StringBuilder sb = new StringBuilder();
for (byte b : packetBytes) {
sb.append(String.format("%02X ", b)).append(" ");//there's no need to mask it with 0xFF. Don't forget to leave a " " between bytes so you may distinguish them.
}
Log.d("data","data"+sb.toString());
handler.post(new Runnable()
{
public void run()
{
//ByteArrayInputStream imageStream = new ByteArrayInputStream( packetBytes);
// Bitmap bitmap = BitmapFactory.decodeStream(imageStream);
// image.setImageBitmap(bitmap);
}
});
}
}
catch (IOException ex)
{
stopWorker = true;
}
}
}
});
workerThread.start();
}
What i am getting is that:
6163206339203564203264203138203...........
463206620666620643920
How to show the actual result(hex values) in logcat and then show the jpg image from the hex value??
I send jpg image data from camera using the following code: main.cpp http://pastebin.com/Tx8YkbYF JPEGCamera.cpp http://pastebin.com/0jHQ8WvT