Skip to content

Instantly share code, notes, and snippets.

@RedRussianBear
Created November 26, 2018 17:02
Show Gist options
  • Save RedRussianBear/6855bff007571536e0a745c79bf020e3 to your computer and use it in GitHub Desktop.
Save RedRussianBear/6855bff007571536e0a745c79bf020e3 to your computer and use it in GitHub Desktop.
public void takePicture(View view) {
// Create intent to open camera app
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Proceed only if there is a camera app
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Attempt to allocate a file to store the photo
File photoFile;
try {
File storageDir = getFilesDir();
photoFile = File.createTempFile("SNAPSHOT", ".jpg", storageDir);
photoPath = photoFile.getAbsolutePath();
} catch (IOException ex) { return; }
// Send off to the camera app to get a photo
Uri photoURI = FileProvider.getUriForFile(this, "com.example.clarifaialarm.fileprovider", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment