android - Camera.open() 获取“访问权限已被限制”
问题描述
- 带有 Android 7.1.1 的诺基亚 6 上发生的问题
- 许可授予
AppOpsManager#checkOp(AppOpsManager.OPSTR_CAMERA, Process.myUid(), getPackageName())
返回AppOpsManager#MODE_ALLOWED
然而,当尝试 Camera.open(i) 检查相机属性时,我得到
I/CameraService:Camera 0:“包裹”的访问受到限制
显然,这只有在应用程序的包或 uId 已被明确限制启动 AppOpsManager#OP_CAMERA 时才会发生 [1]。但是为什么会这样呢?后AppOpsManager#checkOp
说AppOpsManager#MODE_ALLOWED
示例代码
for (int i = 0; i < numCameras; ++i) {
List<Size> supportedSizes = null;
List<int[]> supportedFpsRanges = null;
Camera camera = null;
try {
camera = Camera.open(i);
Parameters parameters = camera.getParameters();
supportedSizes = parameters.getSupportedPreviewSizes();
supportedFpsRanges = getFpsRangesRobust(parameters);
} catch (Exception e) {
...
} finally {
if (camera != null) {
camera.release();
}
}
解决方案
显然这是一个设备问题。诺基亚 6 / TA-1000,安卓 7.1.1
情景
- 尝试使用相机
- 应用程序请求许可,点击拒绝
- 尝试使用相机
- 应用程序请求许可,点击允许
- 在 logcat 中发布错误,相机无法工作
可通过任何其他应用程序重现,包括默认相机应用程序。
推荐阅读
- r - 使用 formattable 的更多样式问题
- python-3.x - Python 的命名空间包在本地开发项目中不可见
- c# - 从文本文件或作为类获取属性
- c# - 我想在 Literal createWizard 中更改 requiresUniqueEmail 错误文本
- r - 前瞻性股票日志回报
- go - go中如何从当前目录导入文件
- c# - C#人名检查和匹配算法
- mysql - sql查询中的混乱
- c++ - 如何在 GCC 中启用 C/C++“带有省略操作数的条件”(又名猫王运算符“?:”)
- javascript - 我在参数列表后收到 Uncaught SyntaxError: missing )