It can be done with the File plugin, but there are a few moving parts to get it working properly:
- You need to write to a sandboxed directory (either
cordova.file.externalDataDirectory
or cordova.file.dataDirectory
), as of Android 10/11.
- You need to add
WRITE_EXTERNAL_STORAGE
permission to your config.xml
(to add to your Android app's manifest.xml
)
- You need to have the appropriate runtime permission as well if you're accessing external storage.
(see How to get documents in an android directory that PhoneGap will see for code snippets)
- Having done that, you'll be working with the FileWriter to write the text to a Blob.
If you need a leg up, you can take a look at my app (I've got a text writer at about line 3239 of this file: https://github.com/adapt-it/adapt-it-mobile/blob/master/www/js/views/DocumentViews.js). It also handles copying the text to the clipboard using the Cordova-clipboard
plugin, which might be of use.