Example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE

List of usage examples for android.provider MediaStore ACTION_IMAGE_CAPTURE

Introduction

In this page you can find the example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE.

Prototype

String ACTION_IMAGE_CAPTURE

To view the source code for android.provider MediaStore ACTION_IMAGE_CAPTURE.

Click Source Link

Document

Standard Intent action that can be sent to have the camera application capture an image and return it.

Usage

From source file:org.telegram.ui.Components.ImageUpdater.java

public void openCamera() {
    if (parentFragment == null || parentFragment.getParentActivity() == null) {
        return;//from   w w  w .jav a  2s.  c  om
    }
    try {
        if (Build.VERSION.SDK_INT >= 23 && parentFragment.getParentActivity()
                .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            parentFragment.getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA },
                    19);
            return;
        }
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File image = AndroidUtilities.generatePicturePath();
        if (image != null) {
            if (Build.VERSION.SDK_INT >= 24) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(
                        parentFragment.getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image));
                takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
            }
            currentPicturePath = image.getAbsolutePath();
        }
        parentFragment.startActivityForResult(takePictureIntent, 13);
    } catch (Exception e) {
        FileLog.e(e);
    }
}

From source file:com.team.formal.eyeshopping.MainActivity.java

public void startCamera() {
    if (PermissionUtils.requestPermission(this, CAMERA_PERMISSIONS_REQUEST,
            Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri photoUri = FileProvider.getUriForFile(getApplicationContext(),
                getApplicationContext().getPackageName() + ".provider", getCameraFile());
        intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivityForResult(intent, CAMERA_IMAGE_REQUEST);
    }//from   w  w w .  j  a va  2 s .  co m
}

From source file:org.catrobat.catroid.ui.dialogs.NewSpriteDialog.java

private void setupCameraButton(View parentView) {
    View cameraButton = parentView.findViewById(R.id.dialog_new_object_camera);

    cameraButton.setOnClickListener(new View.OnClickListener() {

        @Override/*from ww  w .jav a2s .c om*/
        public void onClick(View view) {
            lookUri = UtilCamera.getDefaultLookFromCameraUri(getString(R.string.default_look_name));

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, lookUri);
            startActivityForResult(intent, REQUEST_TAKE_PICTURE);
        }
    });
}

From source file:ca.ualberta.app.activity.CreateAnswerActivity.java

/**
 * Create a storage for the picture in the answer
 * /*w  ww.j a  v  a 2  s.  c  o  m*/
 * @param view
 *            View passed to the activity to check which button was pressed.
 */
public void take_answer_pic(View view) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Create a folder to store pictures
    String folder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp";
    File folderF = new File(folder);
    if (!folderF.exists()) {
        folderF.mkdir();
    }

    // Create an URI for the picture file
    String imageFilePath = folder + "/" + String.valueOf(System.currentTimeMillis()) + ".jpg";
    File imageFile = new File(imageFilePath);
    imageFileUri = Uri.fromFile(imageFile);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);

    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

}

From source file:com.silentcircle.contacts.detail.PhotoSelectionHandler.java

/**
 * Constructs an intent for capturing a photo and storing it in a temporary file.
 *///w  w  w .j  av  a2 s. c  om
private static Intent getTakePhotoIntent(String fileName) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
    final String newPhotoPath = ContactPhotoUtils.pathForNewCameraPhoto(fileName);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(newPhotoPath)));
    return intent;
}

From source file:org.matrix.console.activity.RoomActivity.java

/**
 * Launch the camera//w  w  w  .j  a v a2 s  .c o m
 */
private void launchCamera() {
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // the following is a fix for buggy 2.x devices
    Date date = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, CAMERA_VALUE_TITLE + formatter.format(date));
    // The Galaxy S not only requires the name of the file to output the image to, but will also not
    // set the mime type of the picture it just took (!!!). We assume that the Galaxy S takes image/jpegs
    // so the attachment uploader doesn't freak out about there being no mimetype in the content database.
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    Uri dummyUri = null;
    try {
        dummyUri = RoomActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                values);

        if (null == dummyUri) {
            Log.e(LOG_TAG, "Cannot use the external storage media to save image");
        }
    } catch (UnsupportedOperationException uoe) {
        Log.e(LOG_TAG,
                "Unable to insert camera URI into MediaStore.Images.Media.EXTERNAL_CONTENT_URI - no SD card? Attempting to insert into device storage.");
    } catch (Exception e) {
        Log.e(LOG_TAG, "Unable to insert camera URI into MediaStore.Images.Media.EXTERNAL_CONTENT_URI. " + e);
    }

    if (null == dummyUri) {
        try {
            dummyUri = RoomActivity.this.getContentResolver()
                    .insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
            if (null == dummyUri) {
                Log.e(LOG_TAG, "Cannot use the internal storage to save media to save image");
            }

        } catch (Exception e) {
            Log.e(LOG_TAG, "Unable to insert camera URI into internal storage. Giving up. " + e);
        }
    }

    if (dummyUri != null) {
        captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, dummyUri);
        Log.d(LOG_TAG, "trying to take a photo on " + dummyUri.toString());
    } else {
        Log.d(LOG_TAG, "trying to take a photo with no predefined uri");
    }

    // Store the dummy URI which will be set to a placeholder location. When all is lost on samsung devices,
    // this will point to the data we're looking for.
    // Because Activities tend to use a single MediaProvider for all their intents, this field will only be the
    // *latest* TAKE_PICTURE Uri. This is deemed acceptable as the normal flow is to create the intent then immediately
    // fire it, meaning onActivityResult/getUri will be the next thing called, not another createIntentFor.
    RoomActivity.this.mLatestTakePictureCameraUri = dummyUri == null ? null : dummyUri.toString();

    RoomActivity.this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            startActivityForResult(captureIntent, TAKE_IMAGE);
        }
    });
}

From source file:com.snappy.CameraCropActivity.java

public void startCamera() {
    // Check if camera exists
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Toast.makeText(this, R.string.no_camera, Toast.LENGTH_LONG).show();
        finish();//from  ww w .j a  va  2 s .co m
    } else {
        try {
            long date = System.currentTimeMillis();
            String filename = DateFormat.format("yyyy-MM-dd_kk.mm.ss", date).toString() + ".jpg";
            _path = this.getExternalCacheDir() + "/" + filename;
            File file = new File(_path);
            //            File file = new File(getFileDir(getBaseContext()), filename);
            Uri outputFileUri = Uri.fromFile(file);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(intent, CAMERA);
        } catch (Exception ex) {
            Toast.makeText(this, R.string.no_camera, Toast.LENGTH_LONG).show();
            finish();
        }

    }
}

From source file:com.sanparks.sanscan.WizardEntryActivity.java

private void takePhoto() {
    // We must specify a destination path for an image.
    final File photo = new File(Environment.getExternalStorageDirectory(), genPhotoFileName());

    _imageUri = Uri.fromFile(photo);//from  w  w  w. ja va2 s  .co  m

    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            _imageUri);

    startActivityForResult(intent, PickImageActivity.REQUEST_CODE_TAKE_PHOTO);
}

From source file:org.linphone.ContactEditorFragment.java

private void pickImage() {
    imageToUploadUri = null;//from   w  w  w .ja  va 2  s .c  o  m
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
    imageToUploadUri = Uri.fromFile(file);
    captureIntent.putExtra("crop", "true");
    captureIntent.putExtra("outputX", 256);
    captureIntent.putExtra("outputY", 256);
    captureIntent.putExtra("aspectX", 0);
    captureIntent.putExtra("aspectY", 0);
    captureIntent.putExtra("scale", true);
    captureIntent.putExtra("return-data", false);
    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
    cameraIntents.add(captureIntent);

    final Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    final Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

    startActivityForResult(chooserIntent, ADD_PHOTO);
}

From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java

/**
 * take picture/*from   w ww  .  j a v a  2  s .  c o  m*/
 */
public void takePicture(Activity act, int requestCode) throws IOException {

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(act.getPackageManager()) != null) {
        // Create the File where the photo should go
        //File photoFile = createImageFile();
        File photoFile = createImageSaveFile(act);
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        }
    }
    act.startActivityForResult(takePictureIntent, requestCode);

}