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:io.realm.scanner.MainActivity.java

private void dispatchTakePicture() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        File photoFile = null;//from w  ww. java 2 s  . com
        try {
            photoFile = createImageFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (photoFile != null) {
            currentPhotoPath = photoFile.getAbsolutePath();
            Uri photoURI = FileProvider.getUriForFile(this, "io.realm.scanner.fileprovider", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
}

From source file:com.microsoft.assetmanagement.DisplayCarActivity.java

/**
 * Dispatch take picture intent.//from w  w w . j a  va  2  s .co  m
 */
private void dispatchTakePictureIntent() {
    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;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            Log.e("Asset", ex.getMessage());
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, CAMARA_REQUEST_CODE);
        }
    }
}

From source file:com.luke.lukef.lukeapp.fragments.NewSubmissionFragment.java

/**
 * Activates camera intent//from   ww  w .java 2 s  .com
 */
private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getMainActivity().getPackageManager()) != null) {
        // Create the File where the photo should go
        if (photoFile != null) {
            this.photoPath = photoFile.getAbsolutePath();
            // Continue only if the File was successfully created
            Uri photoURI = FileProvider.getUriForFile(getMainActivity(), "com.luke.lukef.lukeapp", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        } else {
            createImageFile();
            dispatchTakePictureIntent();
        }
    }
}

From source file:org.catnut.ui.ComposeTweetActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (!mSlidingPaneLayout.isOpen()) {
        mSlidingPaneLayout.openPane();//from  w w  w . ja va2s.  co m
    }
    switch (item.getItemId()) {
    case R.id.pref:
        startActivity(SingleFragmentActivity.getIntent(this, SingleFragmentActivity.PREF));
        break;
    case R.id.action_gallery:
        // todo: ????Orz
        if (mUris != null && mUris.size() > 0) {
            Toast.makeText(this, getString(R.string.only_one_pic_hint), Toast.LENGTH_LONG).show();
        } else {
            startActivityForResult(new Intent(Intent.ACTION_PICK).setType("image/*"), 1);
        }
        break;
    case R.id.action_shorten:
        shorten();
        break;
    case R.id.action_camera:
        // same as above
        if (mUris != null && mUris.size() > 0) {
            break;
        }
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (intent.resolveActivity(getPackageManager()) != null) {
            mTmpUri = CatnutUtils.createImageFile();
            if (mTmpUri != null) {
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mTmpUri);
            }
            startActivityForResult(intent, CAMERA);
        } else {
            Toast.makeText(this, getString(R.string.device_not_support), Toast.LENGTH_SHORT).show();
        }
        break;
    case R.id.action_discovery:
        int cursor = mText.getSelectionStart();
        mText.getText().append("##");
        mText.setSelection(cursor + 1);
        mText.requestFocus();
        break;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:net.survivalpad.android.ArticleEditActivity.java

@Override
public void onTakePictureClicked(BaseEditorFragment fragment) {
    mEditorFragment = fragment;/*from  w  w w  . ja v a 2s .c o  m*/

    fileUri = MediaUtils.getOutputMediaFileUri();

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
}

From source file:com.game.simple.Game3.java

public static void camera() {

    self.runOnUiThread(new Runnable() {

        @Override//from  www .  jav  a 2s  . c om
        public void run() {
            try {
                //use standard intent to capture an image
                Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                //we will handle the returned data in onActivityResult
                self.startActivityForResult(captureIntent, CAMERA_CAPTURE);
            } catch (ActivityNotFoundException anfe) {
                //display an error message
                String errorMessage = "?in thoi khng h tr !";
                Toast toast = Toast.makeText(self, errorMessage, Toast.LENGTH_SHORT);
                toast.show();
            }
        }
    });

}

From source file:com.example.deii.Fragments.UpdateProfileFragment.java

protected void startCamera() {
    // TODO Auto-generated method stub
    profileImageCaptured = new File(Environment.getExternalStorageDirectory() + "/" + "temp.png");
    if (profileImageCaptured.exists())
        profileImageCaptured.delete();/*from   ww  w .j av  a  2 s .c  om*/

    outputFileUri = Uri.fromFile(profileImageCaptured);
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, CAMERA_REQUEST);

}

From source file:com.zira.registration.DocumentUploadActivity.java

protected void selectImage() {

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

    AlertDialog.Builder builder = new AlertDialog.Builder(DocumentUploadActivity.this);
    builder.setTitle("Add Photo!");
    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override/*  w  ww.  j a  v  a2s  .  c  om*/
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
                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;
                    try {
                        mCurrentPhotoPath = Util.createImageFile();
                        photoFile = new File(mCurrentPhotoPath);
                    } catch (Exception ex) {
                        // Error occurred while creating the File
                        ex.printStackTrace();
                    }
                    // Continue only if the File was successfully created
                    if (photoFile != null) {
                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                        startActivityForResult(takePictureIntent, 1);
                    }
                }
            } else if (options[item].equals("Choose from Gallery")) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();

}

From source file:com.ceino.chaperonandroid.activities.LicenseActivity.java

private void selectImage() {
    final CharSequence[] options = { "Take Photo", "Choose from Gallery", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Add Photo!");
    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override/*from   w  w w .j  av  a2s . c  o m*/
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File f = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                startActivityForResult(intent, 1);
            } else if (options[item].equals("Choose from Gallery")) {
                Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, 2);

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

From source file:com.harmazing.aixiumama.activity.ActivityGallery.java

/**
 * ??/*  w ww  . j av  a  2 s.co m*/
 */
private void takePhoto() {
    //??SD??
    String SDState = Environment.getExternalStorageState();
    if (SDState.equals(Environment.MEDIA_MOUNTED)) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//"android.media.action.IMAGE_CAPTURE"
        ContentValues values = new ContentValues();
        photoUri = this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
        CuteApplication.tempUri = photoUri;
        startActivityForResult(intent, SELECT_PIC_BY_TACK_PHOTO);
    } else {
        Toast.makeText(this, "??", Toast.LENGTH_LONG).show();
    }
}