-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File Size coming as 0 in android 11 #314
Comments
I've got this too. I believe it's related to changes to Android's new filesystem permissions in 11. See this long thread over at apache/cordova-plugin-file#426 for some info on how other plugins are battling it out: I haven't found a solution yet but I'll add some info here if I find anything. Others have been juggling the API version to work around it but that's no longer an option for those publishing to Google Play. Here's relevant logging info from
and
Here's the full log:
|
Thanks for the investigation @sc0ttdav3y This matches my findings, the external root directory The problematic line is
If external media is mounted (which virtually all phones have external media due to emulation, hence the Personally, I'm not sure on the original rationale. We should never write to an external medium unless explicitly requested. |
I've got a local working solution for Android 11, and linked a draft PR for your review: I don't have the capacity to test this across lots of devices and OSs, so I can't check all the PR boxes. |
any updates of this? have same problem |
the solution that worked for me: since API 30 Android has restrictions on access to external storage. install file plugin : cordova plugin add cordova-plugin-file var onSuccess = function (e) { window.resolveLocalFileSystemURL(cordova.file.dataDirectory,function (directory) and it works for me !!!!! |
Bug Report
On Android below 11 works fine and size also comes perfect but on android 11 size always comes as 0
Problem
What is expected to happen?
It should record the file and should be able to show file size more than 0
What does actually happen?
Not working in android 11
Information
Any more information needed please feel free to ask.
Command or Code
recordAudio(){
let extension ='wav' // 'm4a' 'mp3'
this.file.createFile(this.file.dataDirectory, '111file.'+extension, true).then(() => {
this.myFile = this.media.create(this.file.dataDirectory+'111file.'+extension,);
console.log('filepath',this.file.dataDirectory+'111file.'+extension)
console.log("this.myFile",this.myFile)
this.myFile.startRecord();
alert('started recording')
}).catch(err=>{
console.log('createFile err',err)
});
async stopRecording(){
let extension = 'wav'// 'm4a' 'mp3'
alert('stop called')
this.myFile.stopRecord()
setTimeout(() => {
let duration = this.myFile.getDuration();
console.log(duration);
console.log("this.myFile2",this.myFile)
this.file.readAsDataURL(this.file.dataDirectory, '111file.'+extension).then(res=>{
console.log("checkFile res",res)
let url = this.file.dataDirectory+'111file.'+extension
this.file.resolveLocalFilesystemUrl(url).then(fileEntry => {
fileEntry.getMetadata((metadata) => {
console.log("size",metadata.size);//metadata.size is the size in bytes
})
})
}).catch(err=>{
console.log("checkFile err",err)
})
}, 1000);
}
Environment, Platform, Device
Device used: Oneplus 9R
OS: Android 11
Version information
Project based on ionic 3
cordova 10.0.0
ionic 5.4.13
"cordova-plugin-file": "^6.0.2",
"cordova-android": "8.1.0",
"@ionic-native/media": "^4.20.0",
"cordova-plugin-media": "^5.0.3",
"typescript": "2.8.4"
Checklist
The text was updated successfully, but these errors were encountered: