Example usage for android.provider MediaStore EXTRA_OUTPUT

List of usage examples for android.provider MediaStore EXTRA_OUTPUT

Introduction

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

Prototype

String EXTRA_OUTPUT

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

Click Source Link

Document

The name of the Intent-extra used to indicate a content resolver Uri to be used to store the requested image or video.

Usage

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: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/* w  w  w .j  ava2  s.co 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.liferay.mobile.screens.viewsets.defaultviews.ddl.form.fields.DDLDocumentFieldView.java

@NonNull
private Action1<Boolean> launchCamera(final String intent) {
    return new Action1<Boolean>() {
        @Override/*from w  w  w.  j a va2 s .  c  o  m*/
        public void call(Boolean result) {
            if (result) {
                Intent cameraIntent = new Intent(intent);
                File file = MediaStore.ACTION_VIDEO_CAPTURE.equals(intent) ? FileUtil.createVideoFile()
                        : FileUtil.createImageFile();

                if (file != null) {
                    getField().createLocalFile(file.getAbsolutePath());
                    Uri photoURI = FileProvider.getUriForFile(getContext(),
                            getContext().getPackageName() + ".screensfileprovider", file);
                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);

                    Activity activity = LiferayScreensContext.getActivityFromContext(getContext());
                    activity.startActivityForResult(cameraIntent, positionInForm);
                }
            }
            choseOriginDialog.dismiss();
        }
    };
}

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

private void setIndex(int index) {
    nowIndex = index;//from   w  w w. jav a  2 s . c o m

    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.google.cloud.solutions.smashpix.MainActivity.java

  /**
 * Takes a picture and stores the image locally.
 *//*from  ww w  .  j  a v  a  2  s  .co m*/
public void takePicture()  {
  String timeStamp = new SimpleDateFormat(DATETIME_FORMAT).format(new Date());
  String imageFileName = CAMERA_FILENAME_PREFIX + timeStamp + JPEG_EXTENSION;
  imageStoragePath = new File(imageStorageDirectory, imageFileName);
  Uri imageStorageUri = Uri.fromFile(imageStoragePath);

  Intent intent = new Intent(IMAGE_CAPTURE_INTENT);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, imageStorageUri);
  startActivityForResult(intent, Constants.TAKE_PICTURE);
}

From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java

private void loadInput() {
    Intent intent = getIntent();//from  w  ww.  j a va 2  s . c o m
    Bundle extras = intent.getExtras();

    if (extras != null) {
        aspectX = extras.getInt(Crop.Extra.ASPECT_X);
        aspectY = extras.getInt(Crop.Extra.ASPECT_Y);
        maxX = extras.getInt(Crop.Extra.MAX_X);
        maxY = extras.getInt(Crop.Extra.MAX_Y);
        saveUri = extras.getParcelable(MediaStore.EXTRA_OUTPUT);
    }

    sourceUri = intent.getData();
    if (sourceUri != null) {
        exifRotation = CropUtil
                .getExifRotation(CropUtil.getFromMediaUri(this, getContentResolver(), sourceUri));

        InputStream is = null;
        try {
            sampleSize = calculateBitmapSampleSize(sourceUri);
            is = getContentResolver().openInputStream(sourceUri);
            BitmapFactory.Options option = new BitmapFactory.Options();
            option.inSampleSize = sampleSize;
            rotateBitmap = new RotateBitmap(BitmapFactory.decodeStream(is, null, option), exifRotation);
        } catch (IOException e) {
            Log.e("Error reading image: " + e.getMessage(), e);
            setResultException(e);
        } catch (OutOfMemoryError e) {
            Log.e("OOM reading image: " + e.getMessage(), e);
            setResultException(e);
        } finally {
            CropUtil.closeSilently(is);
        }
    }
}

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 . jav  a2 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:cn.xcom.helper.activity.AuthorizedActivity.java

private void showPickDialog() {
    new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT)
            .setNegativeButton("", new DialogInterface.OnClickListener() {
                @Override//from   w  ww  . ja v  a 2 s .c o m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Intent albumIntent = new Intent();
                    albumIntent.setType("image/*");
                    albumIntent.setAction(Intent.ACTION_PICK);
                    startActivityForResult(albumIntent, PHOTO_REQUEST_ALBUM);
                }
            }).setPositiveButton("?", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    int permissionCheck = ContextCompat.checkSelfPermission(mContext,
                            Manifest.permission.CAMERA);
                    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
                        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        String state = Environment.getExternalStorageState();
                        if (state.equals(Environment.MEDIA_MOUNTED)) {
                            File path = Environment
                                    .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                            File file = new File(path, "51helper.jpg");
                            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                        }
                        startActivityForResult(cameraIntent, PHOTO_REQUEST_CAMERA);
                    } else if (permissionCheck == PackageManager.PERMISSION_DENIED) {
                        // Should we show an explanation?
                        if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) mContext,
                                Manifest.permission.CAMERA)) {

                            // Show an expanation to the user *asynchronously* -- don't block
                            // this thread waiting for the user's response! After the user
                            // sees the explanation, try again to request the permission.

                        } else {

                            // No explanation needed, we can request the permission.

                            ActivityCompat.requestPermissions((Activity) mContext,
                                    new String[] { Manifest.permission.CAMERA },
                                    MY_PERMISSIONS_REQUEST_READ_CONTACTS);

                            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
                            // app-defined int constant. The callback method gets the
                            // result of the request.
                        }
                    }

                }
            }).show();
}

From source file:java_lang_programming.com.android_media_demo.ImageSelectionCropDemo.java

/**
 * start Crop//from   w  ww.j ava  2  s.co  m
 *
 * @param uri image uri
 */
private void startCrop(Uri uri) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("aspectX", 16);
    intent.putExtra("aspectY", 9);
    intent.putExtra("scaleUpIfNeeded", true);
    intent.putExtra("scale", "true");
    intent.putExtra("return-data", false);
    intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.name());
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getExternalStorageTempStoreFilePath()));
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    startActivityForResult(intent, ImageSelectionCropDemo.REQUEST_CODE_CROP);
}

From source file:com.example.d062654.faciliman._2_IncidentPicture.java

private void captureImage() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (intent.resolveActivity(ll.getContext().getPackageManager()) != null) {
        // Create the File where the photo should go

        try {/*from w  w  w.j  a  v  a  2 s.  c o m*/
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File

        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(ll.getContext(), "com.d062654.fileprovider", photoFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(intent, REQUEST_TAKE_PHOTO);
        }
    }

}