Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //set up an intent to take a picture
- private void dispatchTakePictureIntent() {
- log("in dispatchTakePictureIntent()");
- Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- // Ensure that there's a camera activity to handle the intent
- if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
- // Create the File where the photo should go
- File photoFile = null;
- try {
- photoFile = createImageFile();
- } catch (IOException ex) {
- // Error occurred while creating the File
- log("Exception caught. Aborting image creation" + ex);
- }
- // Continue only if the File was successfully created
- if (photoFile != null) {
- takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
- Uri.fromFile(photoFile));
- startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
- }
- }
- }
- //set up a file for the impending picture
- private File createImageFile() throws IOException {
- log("in createImageFile()");
- // Create an image file name
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
- String imageFileName = "JPEG_" + timeStamp + "_";
- File storageDir = Environment.getExternalStoragePublicDirectory(
- Environment.DIRECTORY_PICTURES);
- File image = File.createTempFile(
- imageFileName, /* prefix */
- ".jpg", /* suffix */
- storageDir /* directory */
- );
- // Save a file: path for use with ACTION_VIEW intents
- mCurrentPhotoPath = "file:" + image.getAbsolutePath();
- return image;
- }
- //Snippet of manifest file
- <uses-sdk
- android:minSdkVersion="18"
- android:targetSdkVersion="18" />
- <uses-feature
- android:name="android.hardware.camera"
- android:required="true" />
- <uses-permission
- android:name="android.permission.WRITE_EXTERNAL_STORAGE"
- android:maxSdkVersion="18" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement