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.liangxun.university.huanxin.chat.activity.ChatActivity.java

/**
 * ?/*from   w  ww  .  j  a v a  2 s .  c o  m*/
 */
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(),
            getMyApp().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.example.Bama.chat.chatuidemo.activity.ChatActivity.java

/**
 * ?//from w w w. j  ava2  s.  c o  m
 */
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(),
            HCApplication.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.android.mms.ui.MessageUtils.java

public static void capturePicture(Activity activity, int requestCode) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, TempFileProvider.SCRAP_CONTENT_URI);
    activity.startActivityForResult(intent, requestCode);
}

From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java

/**
 * From https://developer.android.com/training/camera/photobasics.html#TaskPath
 *///from   w  w  w .j a  v  a 2  s  .c  om
private void openCamera() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = UIUtils.createImageFile(getContext(), null);
        } catch (IOException ex) {
            // Error occurred while creating the File
            createToastMessage(getString(R.string.ri_open_camera_problem));
            Log.e(TAG, "Couldn't open camera - " + ex);
        }

        // Continue only if the File was successfully created
        if (photoFile != null) {
            // Save a file: path for use with ACTION_VIEW intents
            mImagePath = photoFile.getAbsolutePath();
            mCapturedImageURI = Uri.fromFile(photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
            startActivityForResult(takePictureIntent, ReportConstants.CAPTURE_PICTURE_INTENT);
        }
    }
}

From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.activity.ChatActivity.java

/**
 * ?//from   ww w .j  ava2s.  com
 */
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(),
            HCApplicaton.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:cn.kangeqiu.kq.activity.ChatActivity.java

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

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            BaseApplication.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:org.awesomeapp.messenger.MainActivity.java

void startPhotoTaker() {

    // create Intent to take a picture and return control to the calling application
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
            "cs_" + new Date().getTime() + ".jpg");
    mLastPhoto = Uri.fromFile(photo);//ww  w.  j  a va 2 s.  c  o m
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mLastPhoto);

    // start the image capture Intent
    startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE);
}

From source file:dong.lan.tuyi.activity.ChatActivity.java

/**
 * ?//from   w ww  .  ja  v  a 2s  . co m
 */
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(),
            TuApplication.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.grass.caishi.cc.activity.ChatActivity.java

/**
 * ?//  ww  w .j  a  v  a2  s  .  c  o  m
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        Toast.makeText(getApplicationContext(), "SD????", 0).show();
        return;
    }

    // cameraFile = new File(PathUtil.getInstance().getImagePath(),
    // DemoApplication.getInstance().getUserName()
    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            MyApplication.getInstance().getUser() + 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.ximai.savingsmore.save.activity.AddGoodsAcitivyt.java

private void openCamera() {
    Uri imageUri = null;//from w  ww .jav  a 2s .  c om
    Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    ImageTools.deletePhotoAtPathAndName(FileSystem.getCachesDir(this, true).getAbsolutePath(),
            PreferencesUtils.getString(this, "tempName"));
    String fileName = String.valueOf(System.currentTimeMillis()) + ".jpg";
    PreferencesUtils.putString(this, "tempName", fileName);
    imageUri = Uri.fromFile(new File(FileSystem.getCachesDir(this, true).getAbsolutePath(), fileName));
    openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(openCameraIntent, PICK_FROM_CAMERA);
}