其他分享
首页 > 其他分享> > Android 11 拍照问题

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);
    }

标签:11,拍照,filePath,fileDir,imageUri,intent,File,new,Android
来源: https://www.cnblogs.com/wuren-best/p/14823767.html