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.android.testing.notes.addnote.AddNoteFragment.java

@Override
public void openCamera(String saveTo) {
    // Open the camera to take a picture.
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Check if there is a camera app installed to handle our Intent
    if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) {
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse(saveTo));
        startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE_CAPTURE);
    } else {//  w  w  w  .j av  a  2s  .c o  m
        Snackbar.make(mTitle, getString(R.string.cannot_connect_to_camera_message), Snackbar.LENGTH_SHORT)
                .show();
    }
}

From source file:com.example.photoremark.MainActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.takephoto:
        // ??sdcard
        String status = Environment.getExternalStorageState();
        if (status.equals(Environment.MEDIA_MOUNTED)) {
            try {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                tempFile = String.valueOf(System.currentTimeMillis()) + ".jpg";
                File f = new File(systemInfo.PATH_TEMP, tempFile);
                Uri u = Uri.fromFile(f);
                intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, u);
                startActivityForResult(intent, RESULT_CAPTURE_IMAGE);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(MainActivity.this, "", Toast.LENGTH_LONG).show();
            }/*from w w  w.j  a v a 2  s  .  co  m*/
        } else {
            Toast.makeText(MainActivity.this, "?", Toast.LENGTH_LONG).show();
        }
        break;
    case R.id.create_word_home:
        Intent intent = new Intent(this, VisitActivity.class);
        intent.putExtra(VisitActivity.EXTRA, VisitActivity.TO_HOME);
        startActivity(intent);
        break;
    case R.id.create_word_village:
        Intent intent1 = new Intent(this, VisitActivity.class);
        intent1.putExtra(VisitActivity.EXTRA, VisitActivity.TO_VILLAGE);
        startActivity(intent1);
        break;
    }
}

From source file:com.ichi2.anki.multimediacard.fields.BasicImageFieldController.java

@Override
public void createUI(Context context, LinearLayout layout) {
    mImagePreview = new ImageView(mActivity);

    DisplayMetrics metrics = getDisplayMetrics();

    int height = metrics.heightPixels;
    int width = metrics.widthPixels;

    LinearLayout.LayoutParams p = new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    setPreviewImage(mField.getImagePath(), getMaxImageSize());
    mImagePreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    mImagePreview.setAdjustViewBounds(true);

    mImagePreview.setMaxHeight((int) Math.round(height * 0.4));
    mImagePreview.setMaxWidth((int) Math.round(width * 0.6));

    mBtnGallery = new Button(mActivity);
    mBtnGallery.setText(gtxt(R.string.multimedia_editor_image_field_editing_galery));
    mBtnGallery.setOnClickListener(new View.OnClickListener() {
        @Override/*  w w w  .  j  av a  2 s .  co  m*/
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            mActivity.startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
        }
    });

    mBtnCamera = new Button(mActivity);
    mBtnCamera.setText(gtxt(R.string.multimedia_editor_image_field_editing_photo));
    mBtnCamera.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            File image;
            File storageDir;
            String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US).format(new Date());
            try {
                storageDir = mActivity.getCacheDir();
                image = File.createTempFile("img_" + timeStamp, ".jpg", storageDir);
                mTempCameraImagePath = image.getPath();
                Uri uriSavedImage = FileProvider.getUriForFile(mActivity,
                        mActivity.getApplicationContext().getPackageName() + ".apkgfileprovider", image);

                cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                mActivity.startActivityForResult(cameraIntent, ACTIVITY_TAKE_PICTURE);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    // Chromebooks do not support camera capture yet.
    if (CompatHelper.isChromebook()) {
        mBtnCamera.setVisibility(View.INVISIBLE);
    }

    layout.addView(mImagePreview, android.view.ViewGroup.LayoutParams.FILL_PARENT, p);
    layout.addView(mBtnGallery, android.view.ViewGroup.LayoutParams.FILL_PARENT);
    layout.addView(mBtnCamera, android.view.ViewGroup.LayoutParams.FILL_PARENT);
}

From source file:com.photocitygame.android.ImageActivity.java

protected void doCapture() {
    File f = Environment.getExternalStorageDirectory();
    File dir = new File(f, "photocity");
    if (!dir.exists()) {
        dir.mkdir();//from   w w w  .ja v  a2 s.  c  o  m
    }
    Uri captureUri = Uri.fromFile(new File(dir, "image.jpg"));
    Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    i.putExtra(MediaStore.EXTRA_OUTPUT, captureUri);
    startActivityForResult(i, TAKE_IMAGE);
}

From source file:com.grottworkshop.gwswizardpager.ui.ImageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_page_image, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    imageView = (ImageView) rootView.findViewById(R.id.imageView);

    String imageData = mPage.getData().getString(Page.SIMPLE_DATA_KEY);
    if (!TextUtils.isEmpty(imageData)) {
        Uri imageUri = Uri.parse(imageData);
        imageView.setImageURI(imageUri);
    } else {//from w  w w.j ava  2 s  . com
        imageView.setImageResource(R.drawable.ic_person);
    }

    imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            DialogFragment pickPhotoSourceDialog = new DialogFragment() {
                @NonNull
                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setItems(R.array.image_photo_sources, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            switch (which) {
                            case 0:
                                // Gallery
                                Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
                                photoPickerIntent.setType("image/*");
                                startActivityForResult(photoPickerIntent, GALLERY_REQUEST_CODE);
                                break;

                            default:
                                // Camera
                                mNewImageUri = getActivity().getContentResolver().insert(
                                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
                                Intent photoFromCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                photoFromCamera.putExtra(MediaStore.EXTRA_OUTPUT, mNewImageUri);
                                photoFromCamera.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
                                startActivityForResult(photoFromCamera, CAMERA_REQUEST_CODE);
                                break;
                            }

                        }
                    });
                    return builder.create();
                }
            };

            pickPhotoSourceDialog.show(getFragmentManager(), "pickPhotoSourceDialog");
        }
    });

    return rootView;
}

From source file:ch.hesso.master.sweetcity.activity.report.ReportActivity.java

private void initButtons() {
    capture.setOnClickListener(new View.OnClickListener() {

        @Override//from  w  ww .jav  a  2 s.co m
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, CameraPictureProvider.CONTENT_URI);
            startActivityForResult(cameraIntent, IntentTag.TAKE_PICTURE);
        }

    });

    tagSelection.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent tagIntent = new Intent(getApplicationContext(), TagSelectionActivity.class);
            startActivityForResult(tagIntent, IntentTag.TAG_SELECTION);
        }

    });

    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            submitReport();
        }

    });
}

From source file:com.albedinsky.android.support.intent.ImageIntent.java

/**
 * Creates a new instance of Intent with {@link MediaStore#ACTION_IMAGE_CAPTURE} that can be used
 * to launch a camera app to capture a single image.
 *
 * @param outputUri If not {@code null}, it will be attached to intent as {@link MediaStore#EXTRA_OUTPUT},
 *                  so when the result is received in for example {@link Activity#onActivityResult(int, int, Intent)},
 *                  the <var>outputUri</var> will address to a file which contains the currently
 *                  captured image./*from   w  ww .  j av  a2  s. c o m*/
 * @return New camera intent instance.
 * @see #createCameraIntent(File)
 */
@NonNull
public static Intent createCameraIntent(@Nullable Uri outputUri) {
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (outputUri != null) {
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
    }
    return intent;
}

From source file:com.andrewreitz.encryptedcamera.di.module.AndroidModule.java

@Provides
@CameraIntent
Intent provideCameraIntent() {
    return new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
}

From source file:org.awesomeapp.messenger.ui.GalleryActivity.java

void startPhotoTaker() {

    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);

    if (permissionCheck == PackageManager.PERMISSION_DENIED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {

            View view = findViewById(R.id.gallery_fragment);

            // 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.
            Snackbar.make(view, R.string.grant_perms, Snackbar.LENGTH_LONG).show();
        } else {//from w w w.  j ava 2s.  co m

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

            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA },
                    MY_PERMISSIONS_REQUEST_CAMERA);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {
        // 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);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mLastPhoto);

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

From source file:com.poinsart.votar.VotarMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    System.loadLibrary("VotAR");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    assetMgr = this.getAssets();

    imageView = (ImageView) findViewById(R.id.imageView);
    bar[0] = (ProgressBar) findViewById(R.id.bar_a);
    bar[1] = (ProgressBar) findViewById(R.id.bar_b);
    bar[2] = (ProgressBar) findViewById(R.id.bar_c);
    bar[3] = (ProgressBar) findViewById(R.id.bar_d);

    barLabel[0] = (TextView) findViewById(R.id.label_a);
    barLabel[1] = (TextView) findViewById(R.id.label_b);
    barLabel[2] = (TextView) findViewById(R.id.label_c);
    barLabel[3] = (TextView) findViewById(R.id.label_d);

    wifiLabel = (TextView) findViewById(R.id.label_wifi);

    mainLayout = ((LinearLayout) findViewById(R.id.mainLayout));
    controlLayout = ((LinearLayout) findViewById(R.id.controlLayout));
    imageLayout = ((LinearLayout) findViewById(R.id.imageLayout));

    adjustLayoutForOrientation(getResources().getConfiguration().orientation);

    findViewById(R.id.buttonCamera).setOnClickListener(new View.OnClickListener() {
        @Override/*  w  ww.j a v a2 s .c o  m*/
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

            cameraFileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraFileUri); // set the image file name

            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    });
    findViewById(R.id.buttonGallery).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_REQUEST);
        }
    });
    votarwebserver = new VotarWebServer(51285, this);
    try {
        votarwebserver.start();
    } catch (IOException e) {
        Log.w("Votar MainAct", "The webserver could not be started, remote display wont be available");
    }
}