簡體   English   中英

錯誤的第一個參數類型Uri / FileProvider Fragment

[英]Wrong 1st argument Type Uri/FileProvider Fragment

我正試圖讓cameraFragment.this在片段中工作,但它一直告訴我“錯誤的第一個參數類型等”

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM