Skip to content
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

MediaCapture CaptureVideo immediately closing app on Android 11 #227

Closed
3 tasks
sampalm opened this issue Jul 27, 2021 · 8 comments · Fixed by #232
Closed
3 tasks

MediaCapture CaptureVideo immediately closing app on Android 11 #227

sampalm opened this issue Jul 27, 2021 · 8 comments · Fixed by #232

Comments

@sampalm
Copy link

sampalm commented Jul 27, 2021

Issue Type

  • [ x] Bug Report
  • Feature Request
  • Support Question

Description

Information

I'm working on a project using Ionic 3,x and Angular2. We're trying to use media-capture to record videos and it seems to work fine on any tablet with Android below 11, when we try to record a video using a Galaxy Tab A7 SM-T505 with an Android version 11 last updated at 1st February 2021 the app closes immediately logging out that error:
image

I'm pointing out that that error only occurs with that tablet on that android version in particular.

Command or Code

this.mediaCapture.captureVideo(this.videoOptions).then((mediafile: MediaFile[]) => { console.log('result ', mediafile); });

Environment, Platform, Device

Version information

Cordova CLI, Ionic framework, Android Studio

Checklist

  • [ x] I searched for already existing GitHub issues about this
  • I updated all Cordova tooling to their most recent version
  • [x ] I included all the necessary information above
@PabbleDabble
Copy link

PabbleDabble commented Jul 27, 2021

@sampalm Hello, I'm actually encountering / attempting to patch this same issue in my app.

Please see - #215

It appears the issue is the plugin storing the video in non-local storage location, and then Android 11 doesn't allow the webview to access that data.

Our fix for now, is to fork this code from pull #215 (here : https://github.com/chriskhongqarma/cordova-plugin-media-capture ) and install from there. We're just building / testing this now.

There's some comments on #215 that it is slated to maybe go in with v4.0.0 of this plugin, which is waiting on cordova-android 10.0.0 which just got released last week, I think. ( https://github.com/apache/cordova-android/blob/master/RELEASENOTES.md )

Lemme know if that helps, have any other questions.

@sampalm
Copy link
Author

sampalm commented Jul 28, 2021

Thank you very much @PabbleDabble, you just saved my day haha
I just tested that fix and it seems to be working fine on my Galaxy Tab A7 SM-T505, also still working on my other tablets too.

@viktor-shmigol
Copy link

I'm getting the same error while recording Audio.

java.lang.string java.io.file.getabsolutepath()' on a null object reference

I tried #215, it works without crashing.
However, If I try to open it using https://github.com/pwlin/cordova-plugin-file-opener2 or even file.resolveLocalFilesystemUrl(fileUrl) I will get error: "NOT_FOUND".

ionic3,
cordova-android: 9.1.0
Pixel 4XL, Android 11

@PabbleDabble
Copy link

@viktor-shmigol

I'm getting the same error while recording Audio.

When? On the 3.0.3 version of cordova-plugin-media-capture? That would make sense to me as Android 11 has changed the file securities. That's what #215 was meant to fix for audio/video/image (I think, we only use it for video but looking at the PR it looks like the user made a method to use absolute path - which works with Android 11)

cordova-plugin-file-opener2
file.resolveLocalFilesystemUrl(fileUrl)

That sounds like a different plugin, and I would suggest seeing if they have an update for that.

We've experienced broken file/system path issues for Android 11 (or even just targeting SDK-30) for 4 different plugins now.
This (media capture) is the only one that I've fixed yet.

SDK-30 (Android 11) will HAVE to be targeted for existing app come November 2021. Good luck.

@viktor-shmigol
Copy link

@PabbleDabble I'm using the latest(3.0.3) version of cordova-plugin-media-capture .
My app is crashing after I record a voice.
I agree it's related to storage changes in Android 11.
Android 11 ignores the requestLegacyExternalStorage flag.
See https://developer.android.com/about/versions/11/privacy/storage
Thanks!

@PabbleDabble
Copy link

@viktor-shmigol I'm very sorry for not responding, I must have missed this.

We don't use cordova-plugin-media-capture for audio capture as it had some other issues for us related to Window/iOS/Android consistency.

We're using - https://github.com/apache/cordova-plugin-media - for all our audio.

I would look in the code for cordova-plugin-media-capture in the audio section and see if the changes for #215 need to be also applied to that section as well? I would not be surprised if the user who made that maybe cares more about the video capture and targeted that, and didn't bother to update the audio part? We support audio capture in our app but honestly I don't know who that's useful for as (in my opinion) voice notes are kind of weird way for users to want to capture data.

@juntaocheng
Copy link

@sampalm Hello, I'm actually encountering / attempting to patch this same issue in my app.

Please see - #215

It appears the issue is the plugin storing the video in non-local storage location, and then Android 11 doesn't allow the webview to access that data.

Our fix for now, is to fork this code from pull #215 (here : https://github.com/chriskhongqarma/cordova-plugin-media-capture ) and install from there. We're just building / testing this now.

There's some comments on #215 that it is slated to maybe go in with v4.0.0 of this plugin, which is waiting on cordova-android 10.0.0 which just got released last week, I think. ( https://github.com/apache/cordova-android/blob/master/RELEASENOTES.md )

Lemme know if that helps, have any other questions.

Thank you @PabbleDabble !
You saved my life, too!

@ath0mas
Copy link
Contributor

ath0mas commented Nov 6, 2021

Strange but I got this app crash too for device Android 11/12 but also Android 9 (app built with API 29 and API 30)
capturing audio, and same java.lang.string java.io.file.getabsolutepath()' on a null object reference,

failing:

recorded content seems to be "inside" dirs of these recorder apps and media-capture can not access it

fine:

  • Samsung device with default Samsung audio recorder

recorded content is located in "public" audio dir and media-capture can access it


I am going to create a PR to prevent this NPE caused app crash - while #215 to use FileProvider is a more future proof rework for sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants