This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onClick(View view) { | |
switch (view.getId()) { | |
case R.id.cameraBtn: { | |
isCameraCapture = true; | |
File photoFile = null; | |
try { | |
photoFile = createImageFile(); | |
} catch (IOException ex) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ActivityResultLauncher<Intent> pickerLauncher = registerForActivityResult( | |
new ActivityResultContracts.StartActivityForResult(), | |
new ActivityResultCallback<ActivityResult>() { | |
@Override | |
public void onActivityResult(ActivityResult result) { | |
if (result.getResultCode() == Activity.RESULT_OK) { | |
//image returned | |
} else { | |
//nothing returned |