fix: handle permissions for getUserMedia#1895
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1895 +/- ##
=======================================
Coverage 61.43% 61.43%
=======================================
Files 24 24
Lines 4922 4922
=======================================
Hits 3024 3024
Misses 1898 1898 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
erisu
left a comment
There was a problem hiding this comment.
Overall, the code looks good to me.
I left a couple of change requests. Can you confirm if they're OK?
I also tested the following use case, with and without my suggested changes:
- Create a default Cordova application
- Add the following to
config.xml:
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/*" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
</config-file>
</platform>- Add the following to
index.html:
<video id="video" autoplay playsinline></video>
<script>
navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {
const video = document.getElementById('video');
video.srcObject = stream;
}).catch(error => {
console.error('Camera Access Error:', error);
});
</script>- If
uses-permission/uses-featureare not in the AndroidManifest file, nothing happens when launching the app. - If
uses-permission/uses-featureare defined in the AndroidManifest file, a runtime permission dialog appears when the app launches.
|
Addressed the comments. Where you say "If uses-permission/uses-feature are not in the AndroidManifest file, nothing happens when launching the app.", it should be going to the catch now and you should see the |
closes #1888
The code is based on Capacitor's implementation.
It uses newer
ActivityResultCallback/ActivityResultLauncherinstead of the oldrequestPermissions.This could later on be extended to request geolocation permissions as at the moment it requires the Geolocation plugin to be installed.