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:com.business.rushour.businessapp.RiderMainActivity.java

private void captureImage() {

    final CharSequence[] options = { "Take Photo", "Choose from Gallery", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(RiderMainActivity.this);
    builder.setTitle("Add Photo!");

    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override//from   ww  w .jav  a 2s  .c  o m
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
                try {

                    final Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    //startActivityForResult(cameraIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
                    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

                    // start the image capture Intent
                    startActivityForResult(cameraIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
                }

                catch (ActivityNotFoundException anfe) {
                    String errorMessage = "Whoops - your device doesn't support capturing images!";
                    Toast toast = Toast.makeText(RiderMainActivity.this, errorMessage, Toast.LENGTH_SHORT);
                    toast.show();
                }
            }

            else if (options[item].equals("Choose from Gallery")) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);

                startActivityForResult(intent, PICK_IMAGE_REQUEST);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();
}

From source file:com.suan.weclient.fragment.MassFragment.java

private void setIndex(int index) {
    nowIndex = index;/*from   w  ww.  j  a  v a  2s. com*/

    for (int i = 0; i < 5; i++) {
        indexLayout[i].setSelected(false);
    }

    indexLayout[index].setSelected(true);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    switch (index) {
    case 0:

        fragmentTransaction.replace(R.id.mass_layout_content, massTextFragment);
        break;
    case 1:
        fragmentTransaction.replace(R.id.mass_layout_content, massImgFragment);
        massImgFragment.setSelectPhotoListener(new SelectPhotoListener() {
            @Override
            public void onSelectFromAlbum() {

                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                photoPickerIntent.setType("image/*");
                startActivityForResult(photoPickerIntent, REQUEST_CODE_SELECT_PHOTO);
            }

            @Override
            public void onTakePhoto() {

                Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                String uploadImgPath = Util.getFilePath(UPLOAD_IMG_NAME);
                File out = new File(uploadImgPath);
                capturedImageName = out.getAbsolutePath();
                i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
                startActivityForResult(i, REQUEST_CODE_TAKE_PHOTO);

            }
        });

        break;
    case 2:
        fragmentTransaction.replace(R.id.mass_layout_content, massVoiceFragment);
        break;
    case 3:
        fragmentTransaction.replace(R.id.mass_layout_content, massAPPFragment);

        break;

    case 4:
        fragmentTransaction.replace(R.id.mass_layout_content, massVideoFragment);
        break;
    }

    fragmentTransaction.commit();
}

From source file:com.android.settings.users.EditUserPhotoController.java

private void takePhoto() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    appendOutputExtra(intent, mTakePictureUri);
    mFragment.startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO);
}

From source file:com.my.seams_carv.StartActivity.java

private void dispatchTakePhotoIntent() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (intent.resolveActivity(getPackageManager()) != null) {
        File file = null;/*from ww  w  . j  ava 2  s .c o  m*/
        try {
            file = createImageFile();
        } catch (IOException ex) {
            // DO NOTHING.
            Log.d("xyz", ex.getMessage());
        }

        // Continue only if the File was successfully created.
        if (file != null) {
            // Save the path.
            mPhotoPath = Uri.fromFile(file);

            Log.d("xyz", String.format("Saved file=%s", file.getAbsolutePath()));

            // Specify the authorities under which this content provider can
            // be found. Multiple authorities may be supplied by separating
            // them with a semicolon. Authority names should use a Java-style
            // naming convention (such as com.google.provider.MyProvider) in
            // order to avoid conflicts. Typically this name is the same as
            // the class implementation describing the provider's data
            // structure.
            final String authority = getResources().getString(R.string.file_provider_authority);
            final Uri uri = FileProvider.getUriForFile(this, authority, file);
            Log.d("xyz", String.format("Generated uri=%s", uri));

            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

            startActivityForResult(intent, REQ_TAKE_PHOTO);
        }
    }
}

From source file:it.smartcampuslab.riciclo.FeedbackFragment.java

private void startCamera() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(new File(mediaStorageDir + File.separator + "tmpImg.jpg")));
    startActivityForResult(Intent.createChooser(intent, getString(R.string.feedback_capture)), 100);
}

From source file:org.apache.cordova.Capture.java

/**
 * Sets up an intent to capture images.  Result handled by onActivityResult()
 *//*from ww w. j  a  va  2s .c  o  m*/
private void captureImage() {
    // Save the number of images currently on disk for later
    this.numPics = queryImgDB(whichContentStore()).getCount();

    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    // Specify file so that large image is captured and returned
    File photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), "Capture.jpg");
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));

    this.cordova.startActivityForResult((CordovaPlugin) this, intent, CAPTURE_IMAGE);
}

From source file:com.nextgis.mobile.forms.CameraFragment.java

public void onCapturePhoto() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri fileUri = getOutputMediaFileUri(); // create a file to save the image
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name

    mAngles.clear();/*from   w  ww .j  a v a 2  s .  com*/
    sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_NORMAL);
    // start the image capture Intent
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

From source file:com.eusecom.attendance.StorageActivity.java

private void launchCamera() {
    Log.d(TAG, "launchCamera");

    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), REQUEST_CODE_CAPTURE_IMAGE);

}

From source file:com.example.linhdq.test.documents.creation.NewDocumentActivity.java

protected void startCamera() {
    try {/*ww  w.j  a va2s. c om*/
        cameraPicUri = null;
        dateCameraIntentStarted = new Date();
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";

        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        File image;
        try {
            if (!storageDir.exists()) {
                storageDir.mkdirs();
            }
            image = new File(storageDir, imageFileName + ".jpg");
            if (image.exists()) {
                image.createNewFile();
            }
            cameraPicUri = Uri.fromFile(image);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, cameraPicUri);
            startActivityForResult(intent, REQUEST_CODE_MAKE_PHOTO);
        } catch (IOException e) {
            showFileError(PixLoadStatus.IO_ERROR);
        }

    } catch (ActivityNotFoundException e) {
        showFileError(PixLoadStatus.CAMERA_APP_NOT_FOUND);
    }
}

From source file:com.example.evan.comp296.messaging.NewPostActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == TC_PICK_IMAGE) {
        if (resultCode == Activity.RESULT_OK) {
            final boolean isCamera;
            if (data.getData() == null) {
                isCamera = true;//w w  w.  ja v  a2  s.  c  om
            } else {
                isCamera = MediaStore.ACTION_IMAGE_CAPTURE.equals(data.getAction());
            }
            if (!isCamera) {
                mFileUri = data.getData();
            }
            Log.d(TAG, "Received file uri: " + mFileUri.getPath());

            mTaskFragment.resizeBitmap(mFileUri, THUMBNAIL_MAX_DIMENSION);
            mTaskFragment.resizeBitmap(mFileUri, FULL_SIZE_MAX_DIMENSION);
        }
    }
}