首页 > 解决方案 > 相机 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);
                    }

标签: javaandroidandroid-camera2android-10.0

解决方案


推荐阅读