I know this question already exists, but I'm not sure how to implement it in my case...
First I created an DataOutuputStream that will write in a file with .uedl extension:
private static DataOutputStream os;
public static final String BASE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myApp/logs/"
public static void startReceiveLogs() {
if (debugBaudRate > -1) {
mReadFlag = true;
String time = TimeUtils.getCurrentTime(TimeZone.getDefault());
try {
os = new DataOutputStream(new FileOutputStream(BASE_PATH + time + "_logs.uedl"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mReceiveLogsThread = new Thread(new ReceiveLogsThread());
mReceiveLogsThread.start();
}
}
Here is the writing stuff:
public void run() {
byte[] rbuf = new byte[64];
while (mReadFlag) {
try {
int len = mSerial.readLog(rbuf, mSerialPortLog);
if (len > 0) {
os.write(rbuf, 0, len);
}
} catch (NullPointerException e1) {
e1.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Once this thread stops running, I'd like to compress that file at the same path.