jonbonazza
Android Expert
Ok, so I am not sure if my problem is spawning from my parsing method or from the thread that contains it, but for some reason, once the file is downloaded, the parsing method doesn't even seem to be called.
My app receives a file via bluetooth and is *supposed* to parse it's contents and take the retrieved coordinates and plot them on a map overlay...
Here is the relevant code.
My thread that watches for incoming files:
Here is my handler that is used int he above thread:
and lastly, here is my parsing method:
Can anyone see what I am doing wrong? I have been trying to fix this problem for days now...
My app receives a file via bluetooth and is *supposed* to parse it's contents and take the retrieved coordinates and plot them on a map overlay...
Here is the relevant code.
My thread that watches for incoming files:
Code:
private class AcceptThread extends Thread
{
private final BluetoothServerSocket mmServerSocket;
public AcceptThread()
{
BluetoothServerSocket tmp = null;
try
{
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord("MYNAME", MY_UUID);
}
catch(IOException e)
{
}
mmServerSocket = tmp;
}
public void run()
{
BluetoothSocket socket = null;
while(true)
{
try
{
socket = mmServerSocket.accept();
}
catch(IOException e)
{
break;
}
if(socket != null)
{
Thread mConnectedThread = new Thread(new ConnectedThread(socket));
mConnectedThread.start();
try
{
mmServerSocket.close();
}
catch (IOException e)
{
}
}
}
}
}
private class ConnectedThread extends Thread {
private final InputStream mmInStream;
public ConnectedThread(BluetoothSocket socket)
{
InputStream tmpIn = null;
// Get the BluetoothSocket input and output streams
try
{
tmpIn = socket.getInputStream();
}
catch (IOException e)
{
}
mmInStream = tmpIn;
}
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.sendMessage(mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer));
List<String> list = readFile();
plotFix(list);
mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DONE));
}
catch (IOException e)
{
break;
}
}
}
}
Here is my handler that is used int he above thread:
Code:
private final Handler mHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
switch(msg.what)
{
case MESSAGE_READ:
byte[] readBuf = (byte[])msg.obj;
FileOutputStream fos;
try
{
fos = new FileOutputStream("/sdcard/.EWA/MBBdata.txt");
fos.write(readBuf);
fos.close();
//plotFix(list);
}
catch (Exception e)
{
}
finally
{
info.setText("Read Successfully");
}
break;
}
}
};
and lastly, here is my parsing method:
Code:
public List<String> readFile()
{
File txtFile = new File("/sdcard/.EWA/MBBdata.txt");
List<String> contents = new ArrayList<String>();
BufferedReader input;
try
{
input = new BufferedReader(new FileReader(txtFile));
String line;
info.setText("working...");
while((line = input.readLine()) != null)
{
contents.add(line);
info.setText("done...");
}
input.close();
}
catch(Exception e)
{
}
return contents;
}
Can anyone see what I am doing wrong? I have been trying to fix this problem for days now...