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

Fix(android): save media capture to File Provider #302

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

XavierMallat
Copy link
Contributor

Platforms affected

Android

Motivation and Context

In an app that I develop, the captured file needs to be moved to a specific app directory. In current plugin version, it works for most Android overlays versions, but for some, it does not (#289, #286, #233, #277, #221, #196 and #210) due to Android's limitation to use external files.
The PR !215 did exactly the job I needed, so I just retrieved @chriskhongqarma's changes and applied them to current master branch with suggestions.

Description

The idea is to use a ContentProvider (a FileProvider, in this case) as a common database to store files, so that both our app and other apps can get access to.
An empty file (audio, image, video) with unique file name (which is generated using current timestamp) and corresponding file format will be created before capturing. Unique file name prevents the file from being duplicated. We use FileProvider to create a Uri for the file, and send it through capturing intents as EXTRA_OUTPUT, so that the created file will be saved with the above Uri. Meanwhile, we store the file absolute path as a global variable, so that it can be used when the intent returns results.
As the file is saved into FileProvider, the app will get access and have control over the created file.

Testing

captureAudio, captureImage, captureVideo features are tested over various Android devices (from Android 10 to Android 14 are covered) using browserstack app live. The app then has full access over the generated media file (move, delete, transcode, etc).

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@breautek breautek added this to the 6.0.0 milestone Dec 3, 2024
@breautek
Copy link
Contributor

breautek commented Dec 5, 2024

Rebasing to pull in #304 should fix the iOS test failures.

@breautek breautek requested a review from erisu December 13, 2024 17:04
@breautek
Copy link
Contributor

Sorry @XavierMallat #295 merge caused the conflict.

If you could rebase again, I have plans to test this PR and merge this week.

xaviermallat added 2 commits December 19, 2024 09:21
- Save image/audio/video to FileProvider instead of MediaStore external storage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants