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

Permissions request on mobile #12041

Closed
c0st1nus opened this issue Dec 24, 2024 Discussed in #12039 · 4 comments
Closed

Permissions request on mobile #12041

c0st1nus opened this issue Dec 24, 2024 Discussed in #12039 · 4 comments

Comments

@c0st1nus
Copy link

Discussed in #12039

Hi everyone,
Just for fun, I made a small project where I want to capture data from the camera, microphone, and geoposition. On desktop, requesting device access through the website was straightforward, and I used the following JavaScript code (Next.js):

useEffect(() => {
    async function getCameraStream() {
        try {
            const stream = await navigator.mediaDevices.getUserMedia({ video: true });
            videoRef.current.srcObject = stream;
            setPermissionGranted(true);
        } catch (err) {
            console.error("Error accessing camera: ", err);
            setError("Permission denied or no camera available.");
        }
    }
    getCameraStream();
}, []);

This worked fine on desktop. But, on mobile I get error catch with "No permission". I found an official "Barcode Scanner" plugin for mobile, but I didn’t fully understand how the permission request for the camera is implemented there.
Could anyone guide me on how to request camera access permission on mobile devices when using Next.js? Are there best practices or specific examples I should follow?
I have already read the issue #4434 . But... I got nothing from it. By that question it would excellent if someone could explain how to request permissions overall.
Thanks in advance!

@FabianLars
Copy link
Member

#10898 (comment)

@c0st1nus
Copy link
Author

#10898 (comment)

Thanks, that solved the most part of problem. However, I’d like to know how to implement the permission request. For example, how can I trigger a dialog to ask for camera permissions in Rust and/or JS?

@FabianLars
Copy link
Member

In js you can just use the web apis == getUserMedia should open the permission requests.

No idea for rust, you'll probably have to dip into kotlin.

@one0oneChen
Copy link

In js you can just use the web apis == getUserMedia should open the permission requests.在 js 中,你可以直接使用 Web API,==getUserMedia 可以打开权限请求。

No idea for rust, you'll probably have to dip into kotlin.没有 rust 的想法,你可能得转向 kotlin 了。

Hello, can you give an example of how to use it

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

No branches or pull requests

3 participants