Skip to content

Instantly share code, notes, and snippets.

View towcar's full-sized avatar

Carson Skjerdal towcar

View GitHub Profile
@towcar
towcar / ImagePickerActivity.java
Created October 23, 2021 21:44
Image Picker Activity createImageFile()
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 */
);
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.cameraBtn: {
isCameraCapture = true;
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
@towcar
towcar / ImagePickerActivity.java
Last active October 23, 2021 21:34
ActivityResultLauncher implementation
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