Hi, I’m buildig an app with Ionic and React. I’ve been stuck for a couple of days now on creating a simple text file. This is the code that I currently have:
setLoading(true);
try {
const test = await Filesystem.writeFile({
path: 'Download/text.txt',
data: 'This is a test',
directory: Directory.External,
encoding: Encoding.UTF8,
recursive: true,
});
console.log(test);
} catch (e) {
console.error(e);
}
setLoading(false);
The loading screen will appear very briefly (I think about 0.2 sec) and then it will finish without any errors. The test
variable logs the following: {uri: "/EXTERNAL/Download/text.txt"}
but the file does not show up anywhere in the device storage. I’ve tested it in the browser, on an android emulator and on a physical android phone and none worked.
I added the following to my AndroidManifest.xml
:
in the application tag:
android:requestLegacyExternalStorage="true"
Permissions part:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"
/>
I use the following packages which might be relevant:
"@capacitor/android": "^3.4.3",
"@capacitor/core": "^3.4.3",
"@capacitor/filesystem": "^1.1.0",
"@ionic/core": "latest",
"@ionic/react": "^5.0.7",
"@ionic-native/android-permissions": "^5.36.0",
"@ionic-native/core": "^5.36.0",
Any one who can help me out please?