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:org.smilec.smile.student.CourseList.java

private void takepicture() {

    chkimg = 1;/*from  w  ww  .j  a v a  2  s  .  c o m*/
    TakenImage = false;

    // check if external storage exist
    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Something else is wrong. It may be one of many other states, but all we need
        //  to know is we can neither read nor write
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }

    if (mExternalStorageAvailable == false || mExternalStorageWriteable == false) {
        showToast("We cannot take picture. Please check if the external storage available or writeable.");
        return;
    }

    // -----------------------------------------------------------------
    // Start Built-in Camera Activity
    // -----------------------------------------------------------------
    // define the file-name to save photo taken by Camera activity
    String img_filename = "new-photo-name.jpg";
    // create parameters for Intent with filename
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, img_filename);
    values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera");
    // imageUri is the current activity attribute, define and save it for
    // later usage (also in onSaveInstanceState)
    imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    // imageUri =
    // getContentResolver().insert(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
    // values);

    // create new Intent
    camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    camera_intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

    startActivityForResult(camera_intent, IMAGECAPTURE_OK);

}

From source file:cn.yunluosoft.tonglou.activity.ChatActivity.java

/**
 * ?//from w  ww .  j a  va 2  s . c  om
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        String st = getResources().getString(R.string.sd_card_does_not_exist);
        Toast.makeText(getApplicationContext(), st, Toast.LENGTH_SHORT).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            MyApplication.getInstance().getUserName() + System.currentTimeMillis() + ".jpg");
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private void startCameraForResult() {
    try {/* ww  w .j  av  a2s .  co m*/
        Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
        String dateString = createTimeStamp();
        photoFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
        i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        startActivityForResult(i, RESULT_CAMERA);
    } catch (Exception e) {
        e.printStackTrace();
        new AlertDialog.Builder(this).setCancelable(true).setTitle(R.string.cannot_open_camera_warning)
                .setMessage("Error: \n" + e.getMessage()).setNegativeButton(R.string.ok, null).create().show();
    }
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Insurance.TlcInsurance.java

private void cameraIntent() {
    if (btnClicked == licenseButton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_LICENSE);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_LICENSE);

    } else if (btnClicked == ssCardButton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_SSCARD);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_SSCARD);
    } else if (btnClicked == baseLetterButton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_BASELETTER);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_BASELETTER);
    } else if (btnClicked == utilityBillsbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_UTILITYBILLS);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_UTILITYBILLS);
    } else if (btnClicked == mvTitlebutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_MVTITLE);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_MVTITLE);
    } else if (btnClicked == sixhrdrivingbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_sixhrdriving);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_sixhrdriving);
    } else if (btnClicked == shlPermitbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_SHLPERMIT);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_SHLPERMIT);
    } else if (btnClicked == shlpermitreceiptbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_SHLRECEIPT);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_SHLRECEIPT);
    } else if (btnClicked == ispermitownedbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_ISPERMITOWNED);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_ISPERMITOWNED);
    } else if (btnClicked == certificatebutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_certificate);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_certificate);
    } else if (btnClicked == fillingbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_filling);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_filling);
    }/*from  w w w  . j  a  va 2 s. c  o  m*/
}

From source file:com.haomee.chat.activity.ChatActivity.java

/**
 * ?//from   ww w .java2s  .  c  om
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        MyToast.makeText(getApplicationContext(), "SD????", 0).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            LiuLianApplication.current_user.getHx_username() + System.currentTimeMillis() + ".jpg");
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}

From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java

private void takePhoto() {
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        final File cache_dir = getExternalCacheDir();
        final File file = new File(cache_dir, "tmp_photo_" + System.currentTimeMillis());
        mTempPhotoUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mTempPhotoUri);
        try {/* w  w w  .  j ava  2s . c  om*/
            startActivityForResult(intent, REQUEST_TAKE_PHOTO);
        } catch (final ActivityNotFoundException e) {
            showErrorMessage(this, null, e, false);
        }
    }
}

From source file:com.keylesspalace.tusky.ComposeActivity.java

private void initiateCameraApp() {
    addMediaBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

    // We don't need to ask for permission in this case, because the used calls require
    // android.permission.WRITE_EXTERNAL_STORAGE only on SDKs *older* than Kitkat, which was
    // way before permission dialogues have been introduced.
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        File photoFile = null;//from   w ww .j av a2  s .c o  m
        try {
            photoFile = createNewImageFile();
        } catch (IOException ex) {
            displayTransientError(R.string.error_media_upload_opening);
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            photoUploadUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileprovider",
                    photoFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUploadUri);
            startActivityForResult(intent, MEDIA_TAKE_PHOTO_RESULT);
        }
    }
}

From source file:com.chaqianma.jd.fragment.CompanyInfoFragment.java

@Override
public void onTakePhoto() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Constants.TEMPPATH);
    if (!file.getParentFile().exists() && !file.mkdirs()) {

    } else {//from w w w. j  a v a2 s.  c o  m
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
        startActivityForResult(intent, REQUEST_TAKE_PHOTO);
    }
}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

void dispatchTakePictureIntentOrShowPicture() {

    ReadingListDetail detail = CommonPlace.currentReadingListDetails.get(mPager.getCurrentItem());
    if (detail.PicturePath == null || detail.PicturePath.equals("")) {

        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Ensure that there's a camera activity to handle the intent
        if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
            // Create the File where the photo should go
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
                ex.toString();/*  w  w  w.j a va 2  s.  co  m*/
                // Error occurred while creating the File
            }
            // Continue only if the File was successfully created
            if (photoFile != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
    } else {
        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        //intent.setDataAndType(Uri.fromFile(file), "image/*");
        intent.setDataAndType(Uri.fromFile(new File(detail.PicturePath)), "image/*");
        startActivity(intent);
    }
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static Intent createPickImageIntent(final Uri uri, final Integer outputX, final Integer outputY,
        final Integer aspectX, final Integer aspectY, final boolean scaleUpIfNeeded) {
    final Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    if (outputX != null && outputY != null) {
        intent.putExtra(CameraCropActivity.EXTRA_OUTPUT_X, outputX);
        intent.putExtra(CameraCropActivity.EXTRA_OUTPUT_Y, outputY);
    }// ww  w  .j a va 2 s  . c om
    if (aspectX != null && aspectY != null) {
        intent.putExtra(CameraCropActivity.EXTRA_ASPECT_X, aspectX);
        intent.putExtra(CameraCropActivity.EXTRA_ASPECT_Y, aspectY);
    }
    intent.putExtra("scale", true);
    intent.putExtra("scaleUpIfNeeded", scaleUpIfNeeded);
    intent.putExtra("crop", "true");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    return intent;
}