Fix(android): save media capture to File Provider #302
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
(platform)
if this change only applies to one platform (e.g.(android)
)