Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native WebView Permissions

Tags:

react-native

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?

like image 378
renren Avatar asked Jun 04 '18 06:06

renren


People also ask

How do you pass data from React Native to Webview?

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.

How Webview works in React Native?

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!


2 Answers

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.

like image 91
Niranjan Balkrishna Prajapati Avatar answered Sep 18 '22 12:09

Niranjan Balkrishna Prajapati


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

like image 25
Daniel Cettour Avatar answered Sep 20 '22 12:09

Daniel Cettour