안드시작한지 얼마 되지 않아서 질문이 많이 허접합니다..
앱을 만드는중 카메라랑 연동해서 촬영후 이미지가 뜨고 다음버튼을 누르는 그런 액티비티를 만드는 중인다
이미지까지 뜨는데 이제 if문으로 이미지가 있는지 없는지 확인후 없으면 toast로 찍어라고 띄우고 싶습니다.
조언 부탁드릴게요ㅠㅠ
@Override
public void onClick(View v) {
if (mCurrentPhotoPath== null) {
Toast.makeText(CameraActivity.this, "사진을 찍어주세요.", Toast.LENGTH_SHORT).show();
return;
} else {
Common.PHOTO_PATH = mCurrentPhotoPath;
Intent intent5 = new Intent(getApplicationContext(), RegistActivity.class);
startActivity(intent5);
}
}
});
void takePicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {
File phtoFile = createImageFile();
Uri photoUri = FileProvider.getUriForFile(this, "com.hionshop.hionevent.fileprovider", phtoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(intent, 0);
} catch (IOException e) {
e.printStackTrace();
}
}
private File createImageFile() throws IOException {
// Create an image file name 이미지 파일 만들기
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageBitmap(BitmapFactory.decodeFile(mCurrentPhotoPath));
}
}
}