errors: expo-camera.isAvailableAsync and expo-camera.getAvailableCameraTypesAsync is not available on android

Viewed 555

expo-camera: "^8.0.0"

sdkVersion: "36.0.0"

Hello people, when i try:

    import { Camera } from 'expo-camera';
    ...
    const cameraIsAvailable = await Camera.isAvailableAsync()
    const availablesCameraTypes = await Camera.getAvailableCameraTypesAsync()
    console.log("cameraIsAvailable: ", cameraIsAvailable)
    console.log("availablesCameraTypes: ", availablesCameraTypes)

i get the fallowing errors:

  1. expo-camera.isAvailableAsync is not available on android, are you sure you've linked all the native dependencies properly?

  2. The method or property expo-camera.getAvailableCameraTypesAsync is not available on android, are you sure you've linked all the native dependencies properly?

enter image description here enter image description here

the problem just disappear when i remove:

state = {
    ...
    cameraType: Camera.Constants.Type.front,
  };
... 
<Camera
            type={this.state.cameraType}
            flashMode={flashMode}
            style={styles.preview}
            ref={camera => this.camera = camera}
          />

and change it by:

state = {
    ...
    cameraType: Camera.Constants.Type.back,
  };

and i change "cameraType" by

componentDidMount = () => {
    this.props.navigation.addListener('didFocus', async () => {
      await setTimeout(() => {
        this.setState({ cameraType: Camera.Constants.Type.front })
      }, 100)
    });
  }

it seems its an error from expo-camera... so when i try to call these methods:

const cameraIsAvailable = await Camera.isAvailableAsync()
    const availablesCameraTypes = await Camera.getAvailableCameraTypesAsync()

i get following errors: errors: expo-camera.isAvailableAsync and expo-camera.getAvailableCameraTypesAsync is not available on android

1 Answers

The methods you're trying to use, Camera.isAvailableAsync and Camera.getAvailableCameraTypesAsync are marked in the documentation as Web only, so calling them will only work, well, on Web.

In code run in react-native context (as opposed to browser context) just check permissions and you should be good to go!

Documentation screenshot

Related