부스트코스 https://www.edwith.org/boostcourse-android/lecture/17103/ 수강중인데요, API 24부터는 Uri.fromfile 이 안된다길래 구글링 해서 filepath xml추가하고 manifest에도 추가를 해서 Fileprovider를 사용하여 카메라를 띄우는데에는 성공하였습니다. 하지만 찍은 사진을 imageview에 추가하고싶은데 받는 resultcode 값이 계속 result_canceled로 나옵니다. filepath xml과 코드 첨부해드리겠습니다.. 방법 해결해주시면 정말 감사하겠습니다.
<코드>
public class MainActivity extends AppCompatActivity {
ImageView imageView;
File file;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
textView = findViewById(R.id.textView);
File dir = Environment.getExternalStorageDirectory();
file = new File(dir,"external_files");
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CameraIntent();
}
});
}
public void CameraIntent(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getApplicationContext(),getApplicationContext().getPackageName()+".provider",file));
startActivityForResult(intent, 1001);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
int code = resultCode;
textView.setText(code+"");
if(requestCode == 1001 && resultCode == RESULT_OK){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap bitmapImage = BitmapFactory.decodeFile(file.getAbsolutePath(),options);
imageView.setImageBitmap(bitmapImage);
}
}
}
<filepath xml 코드>
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>