I forked some parts of @vknow360 's SAF extension, and made a saf text doc handling extension.
I have updated it with the code you have supplied above, you are welcome to test it out - you will probably need a test project...
uk.co.metricrat.textdocsafV1.2.aix (15.5 KB)
(this version is not yet on the github link below)
More info about this extension is available on github here
Thank you! I will try this evening and post the result. (Australia)
I also managed to install rush and compile a modified copy of Sunny's code however it does not compile correctly in app inventor....
Cheers Daryl
In my testing, reads and writes OK for text files on device, reads text file on google drive OK, but does not write it. I think you need google permissions to do this which is outside of SAF, so more blocks needed, and perhaps some google apps script in order to write the file back to google drive.
My version writes to drive however does not truncate even when opening "wt" and calling truncate(0); If I add records, it works as expected, instantly updated on my PC. If I remove rows and save it does not truncate when read by the app or PC however is truncated if I open in android drive.... Think drive has some sync issues.