Good evening, the problem that I can't solve concerns reading text files in Ionic 6 and Android 12 (method readAsText). Using the FilePath, FileChooser and File libraries, the results exist but I can't extract the text (null is returned). Has anyone faced a problem like this before?
The following code worked until a couple of months ago:
//PROPERTY
import { Injectable } from '@angular/core';
import { File } from '@ionic-native/file/ngx';
import { Device } from '@awesome-cordova-plugins/device/ngx';
import { FileChooser } from '@ionic-native/file-chooser/ngx';
import { FilePath } from '@awesome-cordova-plugins/file-path/ngx';
import { Platform } from '@ionic/angular';
import { HttpService } from './http.service';
import { Chooser } from '@awesome-cordova-plugins/chooser/ngx';
//CONSTRUCTOR
public file: File,
public device: Device,
private platform: Platform,
public fileChooser: FileChooser,
private chooser: Chooser,
public http: HttpService,
private filePath: FilePath
....
//SNIPPET WITH ERROR
this.fileChooser
.open()
.then((uri) => {
this.filePath
.resolveNativePath(uri)
.then((url) => {
this.file
.resolveLocalFilesystemUrl(url)
.then((fileEntry: any) => {
this.platform.ready().then(() => {
debugger;
this.file.checkFile(fileEntry['nativeURL'].replace(fileEntry['name'], ''), fileEntry['name']).then(response => {
debugger;
if (response === true) {
this.file
.readAsText(
fileEntry['nativeURL'].replace(fileEntry['name'], ''),
fileEntry['name']
)
.then((result) => {
if (result) {
----> //RESULT ONLY NULL <---------
debugger;
resolve(result);
} else {
reject('Errore');
}
})
.catch((err) => {
console.log('err-->' + JSON.stringify(err));
});
}
}).catch(err => {
debugger;
});
});
});
})
.catch((err_3) => {
reject(err_3);
});
})
.catch((err_2) => {
reject(err_2);
});