简体   繁体   中英

Wrong 1st argument Type Uri/FileProvider Fragment

I'm trying to get cameraFragment.this to work in a Fragment but it keeps telling me "Wrong 1st argument type etc"

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM