首页 > 解决方案 > Expo ImagePicker在android中无法正常工作

问题描述

请求许可componentDidMount

async componentDidMount() {
  await Permissions.askAsync(Permissions.CAMERA);
  await Permissions.askAsync(Permissions.CAMERA_ROLL);
}

照片选择器功能

_takePhoto = async () => {
  let pickerResult = await ImagePicker.launchCameraAsync({
     allowsEditing: true,
     aspect: [4, 3]
   });

  this._handleImagePicked(pickerResult);
 };

渲染区域

<TouchableOpacity onPress={this._takePhoto}>
  <Text> Upload Image </Text>
</TouchableOpacity>

版本

Expo SDK : "^31.0.2"
Tested android version: 7.1

应用程序中的权限

"READ_PHONE_STATE",
"CAMERA",
"READ_INTERNAL_STORAGE",
"WRITE_INTERNAL_STORAGE",
"READ_EXTERNAL_STORAGE",
"WRITE_EXTERNAL_STORAGE"

当我构建 apk 并在设备中运行它时,当我单击按钮时,我的相机没有打开。内部博览会工作正常。

标签: react-nativeexporeact-native-image-picker

解决方案


推荐阅读