I put a website in a webview in react native, the website has a permission in using the camera and audio but the issue is, the permission prompt is not showing in the mobile app, i also tried to enable all the permissions of the app, but still i can't record audio/video. what will be the solution for this?
Now, let's send data from a React Native app to WebView. Create a function called webviewRef and attach it to the WebView component. Next, create a function called sendDataToWebView and add the code below to it. Inside the “script” tag, use window.
WebViews offer developers opportunities to render any web components in a React Native application. A web component can be anything from a whole webpage/application or just a simple HTML file. The package react-native-webview makes it super simple to embed WebViews into your React Native apps!
You have to use PermissionsAndroid
of React-native to ask for permissions
Following is the code for asking permissions :
async checkPermissions() {
await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.CAMERA,
]).then(result => {
console.log('checkPermissions result', result);
});
}
Provide whatever permissions you require in the array and check for their status in result.
If you are using expo, first install:
expo install expo-camera
Then, in your WebView:
import { Camera } from "expo-camera";
export default function MyWebView({ route }) {
Camera.requestCameraPermissionsAsync();
... your webViewCode ...
}
source: https://docs.expo.dev/versions/latest/sdk/camera/#camerarequestcamerapermissionsasync
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With