I am developing an Android Application for a Honeywell CK75 Scanner that saves barcode scans to an XML file stored on the device.
The app is being built for Android SDK level 19. The permissions for accessing the storage are in place
This is the code for the method that creates and saves the XML file.
public static void writeToXMLFile(List<Scan> scans, Context context) throws IOException {
XmlSerializer serializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
serializer.setOutput(writer);
serializer.startDocument("UTF-8", true);
serializer.startTag(null, "Scans");
for(Scan s : scans){
serializer.startTag(null, "Scan");
serializer.startTag(null, "AimID");
serializer.text(s.getAimID());
serializer.endTag(null, "AimID");
serializer.startTag(null, "BarcodeData");
serializer.text(s.getBarcodeData());
serializer.endTag(null, "BarcodeData");
serializer.startTag(null, "BarcodeID");
serializer.text(s.getBarcodeID());
serializer.endTag(null, "BarcodeID");
serializer.startTag(null, "TimeStamp");
serializer.text(s.getTimestamp());
serializer.endTag(null, "TimeStamp");
if(s.getTrailerNo().equals(null) || s.getTrailerNo().isEmpty()){
serializer.startTag(null, "BinNo");
serializer.text(s.getBinNo());
serializer.endTag(null, "BinNo");
}
else{
serializer.startTag(null, "TrailerNo");
serializer.text(s.getTrailerNo());
serializer.startTag(null, "TrailerNo");
}
}
serializer.endDocument();
String result = writer.toString();
String url = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/Scan.xml";
File f = new File(url);
f.getParentFile().mkdir();
f.createNewFile();
FileOutputStream output = new FileOutputStream(f, false);
output.write(result.getBytes(),0,result.length());
output.close();
}
I expect that the file is save to the Documents folder, however when I check that folder, there is no XML file there.
Edit
It just seems like its not creating the file. I have tried several different methods of creating the file, and none have worked. At this point in time, I'm not concerned with whether or not the XML is okay, I am just trying to created a file on Android that can be accessed from a PC