Reputation: 302
I am working in an application that needs to write an .xml
file. Right now the file only gets filled after restarting the Android device
, and I do not understand why. This is my code:
override fun doInBackground(vararg params: Void?): Boolean {
val sagaCollectFolder = File(Environment.getExternalStorageDirectory(), ".sagacollect")
if (!sagaCollectFolder.exists())
sagaCollectFolder.mkdir()
try {
val file = File(
sagaCollectFolder,
"collect.xml"
)
file.createNewFile()
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
val builder: DocumentBuilder = factory.newDocumentBuilder()
val doc: Document = builder.parse(InputSource(StringReader(JRPresenter.getFilledFormXml().toString())))
// Write the parsed document to an xml file
val transformerFactory: TransformerFactory = TransformerFactory.newInstance()
val transformer: Transformer = transformerFactory.newTransformer()
val source = DOMSource(doc)
val result = StreamResult(file)
transformer.transform(source, result)
} catch (exception: Exception) {
Log.e(TAG, exception.toString())
}
return true
}
Here is where I execute the AsyncTask
:
fun saveResult(index: FormIndex, answer: IAnswerData?) {
formController.saveAnswer(index, answer)
WriteCacheAsync().execute()
}
Anyone knows what should I change in order to fill the file after calling the method and not after restarting the device?
Cheers,
Mauricio
Upvotes: 3
Views: 234
Reputation: 302
@blackapps solved my problem:
Wrong method. Because Windows depends on the media store of the Android device and you did not inform the media store about the new file. Indeed the media store scanner will find your file after reboot. Use a file manager app on the device instead. Or check self with code
Using the file manager I've seen that everything was working fine. Thank you all so much.
Upvotes: 1