How can I write to a public folder on Android?


#1

I am trying to write a file to an Android device that can be accessed by the user or apps on the device.
I am currently using FilesystemDirectory.Documents.
The code below writes to:

file:///storage/emulated/0/Documents

However I can’t browse to this location on the device.
Is there a way I can write to a public location?

Code:

const fileName = 'defectreport.pdf';
        try {
          Filesystem.writeFile({
            path: fileName,
            // data: this.pdfBase64,
            data: this.pdfBase64,
            directory: FilesystemDirectory.Documents,
            encoding: FilesystemEncoding.UTF8
          }).then((writeFileResult) => {
            console.log('File Written');
            console.log(writeFileResult);
            Filesystem.getUri({
                directory: FilesystemDirectory.Documents,
                path: fileName
            }).then((getUriResult) => {
                console.log(getUriResult);
                const path = getUriResult.uri;
                this.fileOpener.open(path, 'application/pdf')
                .then(() => console.log('File is opened'))
                .catch(error => console.log('Error openening file', error));
            }, (error) => {
                console.log(error);
            });
          });
          console.log('writeFile complete');
        } catch (error) {
          console.error('Unable to write file', error);
        }