Android 11 拍照问题

安卓11有权限要求,以下方法管用



    //跳转到相机
    private void showCamera() {
        File fileDir = new File(Environment.getExternalStorageDirectory(),"Pictures");
        if (!fileDir.exists()){
            fileDir.getParentFile().mkdir();
        }
        filePath = fileDir.getAbsolutePath() + "/IMG_" + System.currentTimeMillis() + ".jpg";
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (Build.VERSION.SDK_INT > 24){
            imageUri = FileProvider.getUriForFile(this,this.getPackageName() + ".fileprovider",
                    new File(filePath));
        }
        else {
            imageUri = Uri.fromFile(new File(filePath));
        }
        intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
        startActivityForResult(intent,TAKE_PHOTO);
    }

posted @ 2021-05-28 20:42  Nevesettle  阅读(1552)  评论(0编辑  收藏  举报