第一个参数类型Uri / FileProvider片段错误

时间:2019-06-01 00:01:42

标签: java android

我正在尝试让cameraFragment.this在Fragment中工作,但它一直告诉我“错误的第一个参数类型等”

public void dispatchPicTaken(){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if(intent.resolveActivity(getActivity().getPackageManager()) != 
null){
            File imgFile = null;
            imgFile = createPhotoFile();

            if(imgFile != null) {
                pathToFile = imgFile.getAbsolutePath();
                Uri photoURI = 
FileProvider.getUriForFile(cameraFragment.this, "test", imgFile);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(intent, 1);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

您应该使用getActivity()而不是fragment来获取cameraFragment.this中的上下文

FileProvider.getUriForFile(getActivity(), "test", imgFile);