Created
November 26, 2018 17:02
-
-
Save RedRussianBear/6855bff007571536e0a745c79bf020e3 to your computer and use it in GitHub Desktop.
This file contains 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
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