Aggiunto invio del file raw del log nel caso in cui vada in eccezione il parsine

This commit is contained in:
Giuseppe Scorrano 2025-09-15 17:36:37 +02:00
parent 819cc97113
commit ce9d304043

View File

@ -280,15 +280,27 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
List<MailAttachmentDTO> attachmentDTOList = new ArrayList<>();
if (fileToShare != null) {
var htmlContent = createAppLogAttachment(fileToShare);
try {
var htmlContent = createAppLogAttachment(fileToShare);
byte[] buffer = htmlContent.getBytes();//specify the size to allow.
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
byte[] buffer = htmlContent.getBytes();//specify the size to allow.
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
var logAttachment = new MailAttachmentDTO()
.setFileName("wms_log.html")
.setFileb64Content(base64);
attachmentDTOList.add(logAttachment);
var logAttachment = new MailAttachmentDTO()
.setFileName("wms_log.html")
.setFileb64Content(base64);
attachmentDTOList.add(logAttachment);
} catch (Exception ex) {
String rawLogFile = getRawLogAttachment(fileToShare);
byte[] buffer = rawLogFile.getBytes();//specify the size to allow.
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
var logAttachment = new MailAttachmentDTO()
.setFileName("raw_log.txt")
.setFileb64Content(base64);
attachmentDTOList.add(logAttachment);
}
}
@ -461,4 +473,24 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
return htmlContent.toString();
}
private String getRawLogAttachment(File logFile) {
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(logFile));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
} catch (IOException e) {
//You'll need to add proper error handling here
}
return text.toString();
}
}