-
Notifications
You must be signed in to change notification settings - Fork 50
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
Granting device camera access to my website #336
Comments
Hm, your Android code looks good to me. Don't see anything wrong here.
const constraints = {
audio: false,
video: true,
};
navigator.mediaDevices
.getUserMedia(constraints)
.then((mediaStream) => {
const video = document.querySelector("video");
video.srcObject = mediaStream;
video.onloadedmetadata = () => {
video.play();
};
}) Without the |
@leonvogt Thanks for your response. With regards to both your points, I definitely am using |
Hm ok. I see a difference on how you handle the browser permission request. Don't think that's the issue, but I post my code for granting the camera access here anyway: override fun onPermissionRequest(request: PermissionRequest?) {
// if permission request is for camera access
if (request?.resources?.contains(PermissionRequest.RESOURCE_VIDEO_CAPTURE) == true) {
// always grant permission
// depending on the android camera permission, the browser will still get a permission denied error if the user has not granted the permission
request.grant(request.resources)
}
} Without this code, the browser will also get a |
Ah wait, I didn't read your issue text carefully enough.
If the ChromeClient doesn't get invoked, it can't handle the camera permission request, which would explain the I add my ChromeClient a bit differently: @TurboNavGraphDestination(uri = "turbo://fragment/web")
open class WebFragment : TurboWebFragment(), NavDestination {
override fun createWebChromeClient(): TurboWebChromeClient {
return CustomChromeClient(session)
}
} |
@leonvogt You genius! That did it. I clearly missed that TurboWebFragment was doing Really really appreciate your help. I'd been lost for 48 hours over this haha! |
Awesome. I'm happy to hear that it worked! 🎉 |
Can you explain this method in Java language as well? |
Hi 👋
I'm having some issues trying to access Camera capabilities in my Android App. I am building an app where one of the functionalities is to use the camera, display it on the page and scan QR codes using html5-qrcode library. This functionality works fine on the Chrome. However, not as an Android app on an Android device.
I believe I am successfully requesting and granting access to my application for the usage of CAMERA, however, I think my external website which is loaded into the TurboWebView also somehow needs access which it is not getting or even requesting.
To help build a picture, here is some of my code:
Here are the permissions and features specified inside AndroidManifest
MainActivity
As you can see from my override above, I have implemented
onRequestPermissionsResult
where I am consistently getting "Camera Request: Permission granted" which means my application definitely has access.My onSessionCreated() within my MainSessionNavHostFragment (from following demo examples)
As you can see from the above example, I tried to set my own NewWebChromeClient and additionally a javascript interface which you can see below:
The webapp interface also allows me to simply call
AndroidApp.requestCameraPermission()
directly from my stimulus JS controller which works, but again it doesn't actually give permission for my actual website to access the camera.Here is also my custom WebChromeClient which based on putting some logging in there, never actually runs.
Through testing in developer mode using a real device, I can confirm I definitely get the prompt for giving camera permission. Through my debug logs, everything indicates that permission to the app has been granted. However, these lines of logs sadly disagree 😢 :
The last line of log comes from where my library is triggering the JS getUserMedia() function.
I may be just missing something obvious here or I'm being delusional in thinking this is supposed to be straight forward 😂. I really appreciate any guidance or help 🙏
The text was updated successfully, but these errors were encountered: