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.example.fertilizercrm.easemob.chatuidemo.activity.ChatActivity.java

/**
 * ?/*from ww  w.jav  a2 s. co  m*/
 */
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(),
            FertilizerApplication.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.shafiq.mytwittle.view.BaseLaneActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case android.R.id.home:
        if (composeReleaseFocus(false) == true) {
            return true;
        }//from w  w  w  .j a v  a2 s . c  om
        break;

    case R.id.action_gallery: {

        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent, Constant.REQUEST_CODE_IMAGE_PICKER);

        // startActivityForResult(new Intent(Intent.ACTION_PICK,
        // android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI),
        // Constant.REQUEST_CODE_IMAGE_PICKER);
        return true;
    }

    case R.id.action_camera: {

        if (Util.isIntentAvailable(this, android.provider.MediaStore.ACTION_IMAGE_CAPTURE)) {
            Uri tmpUri = Uri.fromFile(getFixedTempFile(BaseLaneActivity.this));
            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, tmpUri);
            startActivityForResult(intent, Constant.REQUEST_CODE_CAMERA);
        }
        return true;
    }

    /*
     * case R.id.action_locate: Toast.makeText(getApplicationContext(),
     * getString(R.string.functionality_not_implemented),
     * Constant.DEFAULT_TOAST_DISPLAY_TIME).show(); break;
     */

    default: {
        BaseLaneFragment fragment = mLaneFragmentHashMap.get(getCurrentLaneIndex());
        if (fragment != null) {
            return fragment.onOptionsItemSelected(item);
        }
    }
    }

    return false;
}

From source file:com.eason.marker.emchat.chatuidemo.activity.ChatActivity.java

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

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            MainApplication.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.tweetlanes.android.core.view.BaseLaneActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int i = item.getItemId();
    if (i == android.R.id.home) {
        if (composeReleaseFocus(false)) {
            clearCompose();//from  w  w  w. j a va 2s .co m
            return true;
        }

    } else if (i == R.id.action_gallery) {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent, Constant.REQUEST_CODE_IMAGE_PICKER);
        return true;
    } else if (i == R.id.action_camera) {
        if (Util.isIntentAvailable(this, MediaStore.ACTION_IMAGE_CAPTURE)) {
            Uri tmpUri = Uri.fromFile(getFixedTempFile(BaseLaneActivity.this));
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, tmpUri);
            startActivityForResult(intent, Constant.REQUEST_CODE_CAMERA);
        }
        return true;

        /*
         * case R.id.action_locate: Toast.makeText(getApplicationContext(),
         * getString(R.string.functionality_not_implemented),
         * Constant.DEFAULT_TOAST_DISPLAY_TIME).show(); break;
         */
    } else {
        BaseLaneFragment fragment = mLaneFragmentHashMap.get(getCurrentLaneIndex());
        if (fragment != null) {
            return fragment.onOptionsItemSelected(item);
        }
    }

    return false;
}

From source file:com.segma.trim.MainActivity.java

private void photoFromCamera() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;//  www  .  j a  va 2 s . co m
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            Toast.makeText(getApplicationContext(), WARNING_CAMERA_IMPORT_ERROR, Toast.LENGTH_LONG).show();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_CODE_CAMERA);
        }
    }
}

From source file:com.fullteem.yueba.app.ui.ChatActivity.java

/**
 * ?//  www  .  j a  va 2  s  .c  om
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        Toast.makeText(getApplicationContext(), "SD????", 0).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            AppContext.getApplication().getUserInfo().getUserAccount() + 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.gongpingjia.carplay.activity.chat.ChatActivity.java

/**
 * ?//from  www.  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, 0).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            User.getInstance().getUserId() + 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.app.khclub.base.easeim.activity.ChatActivity.java

/**
 * ?/*from  w  w  w .  j  a  v  a  2  s  .  co  m*/
 */
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(),
            KHUtils.selfCommonIMID() + 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.hanyu.desheng.activity.ChatActivity.java

/**
 * ?/*from  w ww. jav  a  2  s.co  m*/
 */
@SuppressLint("ShowToast")
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(),
            ExampleApplication.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.ieeton.agency.activity.ChatActivity.java

/**
 * ?/*from  w w w.  j av  a 2  s. co m*/
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        Toast.makeText(getApplicationContext(), "SD????", 0).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            DemoApplication.getInstance().getUserName() + System.currentTimeMillis() + ".jpg");
    if (cameraFile != null && cameraFile.getParent() != null) {
        cameraFile.getParentFile().mkdirs();
    }
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}