java - 相机 API 安卓 10
问题描述
捕获图像时显示错误,我已经授予设备的读写存储权限我正在使用相机意图在 android 10 中拍照,但显示以下错误
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentResolver resolver = getContext().getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "temp");
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, "DCIM/" + "TEMP");
Uri imageUri123 = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
imageUri123);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}else {
File photo = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Build.VERSION.SDK_INT >= Build.VERSION_CODES.M?getOutputMediaFileUri(getActivity(), photo):Uri.fromFile(photo));
startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
}
解决方案
推荐阅读
- javascript - Distinct values from Array inside Array of objects
- java - 为什么Java抽象类中需要受保护的构造函数
- mysql - 我想获得特定飞蛾每天所有产品的总和
- java - 将实体上的条件定义为实体属性上的条件
- java - java.lang.UnsatisfiedLinkError:启用 proguard 时找不到 java.lang.String 的实现
- azure-sql-database - 为什么 Azure 数据工厂似乎坚持将 DateTimes 作为字符串插入?
- python - index 必须是单调递增或递减的
- reactjs - 显示 React Skeleton Loader,直到图像完全加载
- sql-server - 如何从系统版本表中获取多个日期
- vba - 如何逐行修改文件