首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >本机反应:为什么在app.json中设置权限后不能访问摄像机

本机反应:为什么在app.json中设置权限后不能访问摄像机
EN

Stack Overflow用户
提问于 2022-08-09 07:04:07
回答 1查看 246关注 0票数 0

我试图创建一个应用程序,用户可以在按下按钮时拍照。在设置app.json上的相机权限之前,它在我的物理设备上运行得非常好,但是在设置了app.json上的权限之后,它就不能工作了。我仍然得到弹出,它要求用户的许可,但在允许使用相机,它不激活相机。当我再按下按钮的时候,它还是不起作用。

app.json

代码语言:javascript
复制
"plugins": [
      [
        "expo-image-picker",
        {
          "photosPermission": "custom photos permission",
          "cameraPermission": "Allow $(PRODUCT_NAME) to open the camera",
          
          "//": "Disables the microphone permission",
          "microphonePermission": false
        }
      ]
    ],
"android": {
  "package":"mycamera.myapp",
  "versionCode": 2,
  "permissions": ["CAMERA","READ_EXTERNAL_STORAGE"],
  "adaptiveIcon": {
    "foregroundImage": "./assets/adaptive-icon.png",
    "backgroundColor": "#FFFFFF"
  }
}

HomeScreen.js

代码语言:javascript
复制
const [allImage, setAllImage] = React.useState([]);
    const useCamera = async () => {
        const hasPermissions = await cameraPermission();
        if (!hasPermissions) {
            return;
        }
        if(allImage.length < 4){
            let result = await ImagePicker.launchCameraAsync({
                allowsEditing: true,
                quality: 0.5,
            });

            if (!result.cancelled) { 
                const name = result.uri.split('/').pop();
                let match = /\.(\w+)$/.exec(name);
                let type = match ? `image/${match[1]}` : `image`;
                let newFile = {
                    uri: result.uri,
                    type: type,
                    name: name
                }
                
                setAllImage(newFile)
                setPickedImage(result.uri)
                if (!pickedImage && allImage.length === 0) {
                    setAllImage([newFile]); 
                    setFileName("Receipt 1")
                }else {
                    setAllImage([...allImage, newFile]); 
                    setFileName(fileName + ", Receipt " + (allImage.length + 1))  
                }
            }
        }
    };
EN

Stack Overflow用户

回答已采纳

发布于 2022-08-09 08:30:02

对于expo选择器的expo权限,如官方文档所示,您需要创建app.config、js / app.json文件并在那里添加权限。

详细步骤在主页链接-> https://github.com/expo/expo/tree/sdk-46/packages/expo-image-picker中提供。

您需要按以下方式添加权限

从官方网站获取图像权限的app.config.js实例

代码语言:javascript
复制
{

 "expo": {
   "plugins": [
    [
    "expo-image-picker",
    {
      "photosPermission": "custom photos permission",
      "cameraPermission": "Allow $(PRODUCT_NAME) to open the camera",
      "//": "Disables the microphone permission",
      "microphonePermission": false
     }
    ]
  ]
 }
}
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73287699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档