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.hackaton.NuevaQuejaActivity.java

@AfterPermissionGranted(RC_CAMERA_PERMISSIONS)
private void showImagePicker() {
    // Check for camera permissions
    Log.d(TAG, "launchCamera");

    // Check that we have permission to read images from external storage.
    String perm = Manifest.permission.READ_EXTERNAL_STORAGE;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !EasyPermissions.hasPermissions(this, perm)) {
        EasyPermissions.requestPermissions(this,
                "This sample reads images from your camera to demonstrate uploading.", RC_STORAGE_PERMS, perm);
        return;/*from   www  .ja  va 2  s . c om*/
    }

    // Create intent
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Choose file storage location
    File file = new File(Environment.getExternalStorageDirectory(), UUID.randomUUID().toString() + ".jpg");
    mFileUri = Uri.fromFile(file);
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);

    // Launch intent
    startActivityForResult(takePictureIntent, RC_TAKE_PICTURE);
}

From source file:Rangoli.testapp.Feed.NewPostActivity.java

@AfterPermissionGranted(RC_CAMERA_PERMISSIONS)
private void showImagePicker() {
    // Check for camera permissions
    if (!EasyPermissions.hasPermissions(this, cameraPerms)) {
        EasyPermissions.requestPermissions(this, "This sample will upload a picture from your Camera",
                RC_CAMERA_PERMISSIONS, cameraPerms);
        return;/*  w w w.ja  v a 2 s. co m*/
    }

    // Choose file storage location
    File file = new File(getExternalCacheDir(), UUID.randomUUID().toString());
    mFileUri = Uri.fromFile(file);

    // Camera
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);
        cameraIntents.add(intent);
    }

    // Image Picker
    Intent pickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    Intent chooserIntent = Intent.createChooser(pickerIntent, "");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
    startActivityForResult(chooserIntent, TC_PICK_IMAGE);
}

From source file:com.example.android.wardrobe.HomeActivity.java

public void loadImage(final int what) {
    ContextOption[] items = new ContextOption[] {
            new ContextOption("Take picture from camera", R.drawable.camera),
            new ContextOption("Select picture from gallery", R.drawable.gallery) };
    SimpleMenuAdapter contextMenuAdapter = new SimpleMenuAdapter(this, Arrays.asList(items));
    new AlertDialog.Builder(this)
            // .setTitle("Share Appliction")
            .setAdapter(contextMenuAdapter, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int menuId) {
                    Intent intent = null;
                    switch (menuId) {
                    case 0:
                        addWhat = what;/*from  w  w w.  ja  v  a 2s  .c  o  m*/
                        intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                        mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
                                "tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".png"));

                        intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
                        intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name());

                        try {
                            intent.putExtra("return-data", true);

                            startActivityForResult(intent, PICK_FROM_CAMERA);
                        } catch (ActivityNotFoundException e) {
                            e.printStackTrace();
                            /**
                            * TODO show message to user
                            */
                        }
                        break;
                    case 1:
                        addWhat = what;
                        intent = new Intent();

                        intent.setType("image/*");
                        intent.setAction(Intent.ACTION_GET_CONTENT);

                        startActivityForResult(Intent.createChooser(intent, "Complete action using"),
                                PICK_FROM_FILE);
                        break;
                    }
                }
            }).show();
}

From source file:fr.jcf.pret.activities.PretEmpruntActivity.java

/**
 * Permet de lancer l'appareil photo//from   ww w  .ja  v  a  2  s  .c  om
 * 
 * @param view
 */
public void showCamera(View view) {
    Intent intentCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // On cre un objet File et on l'enregistre dans le systme de fichiers
    fileUri = CameraVideoHelper.getOutputMediaFileUri(CameraVideoHelper.MEDIA_TYPE_IMAGE);

    // On ajoute le fichier dans les donnes  transmettre dans l'Intent
    intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

    startActivityForResult(intentCamera, UtilPret.PICK_CAMERA_REQUEST);
}

From source file:com.grupohqh.carservices.operator.ManipulateCarActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manipulate_car);

    if (getIntent().getExtras().containsKey("userId"))
        userId = getIntent().getExtras().getInt("userId");
    if (getIntent().getExtras().containsKey("carOwnerId"))
        carOwnerId = getIntent().getExtras().getInt("carOwnerId");

    CARBRAND_URL = getString(R.string.base_url) + getString(R.string.carbrands_url);
    CARLINE_URL = getString(R.string.base_url) + getString(R.string.carmodels_url);
    SAVECAR_URL = getString(R.string.base_url) + "savecar/";
    SAVEPHOTO_URL = getString(R.string.base_url) + "savephoto/";
    hasCamera = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);

    etTagNumber = (EditText) findViewById(R.id.etTagNumber);
    etUsernameOwner = (EditText) findViewById(R.id.etUsernameOwner);
    etCarBrand = (EditText) findViewById(R.id.etCarBrand);
    etCarModel = (EditText) findViewById(R.id.etCarModel);
    etCarYear = (EditText) findViewById(R.id.etCarYear);
    etColor = (EditText) findViewById(R.id.etCarColor);
    etSerialNumber = (EditText) findViewById(R.id.etSerialNumber);
    etLicensePlate = (EditText) findViewById(R.id.etLicensePlate);
    etKM = (EditText) findViewById(R.id.etKm);
    imgCar = (ImageView) findViewById(R.id.imgCar);
    spCarBrand = (Spinner) findViewById(R.id.spCarBrand);
    spCarModel = (Spinner) findViewById(R.id.spCarModel);
    btnSaveCar = (Button) findViewById(R.id.btnSaveCar);
    btnTakePicture = (Button) findViewById(R.id.btnTakePicture);
    bar = (ProgressBar) findViewById(R.id.progressBar);
    viewUsername = findViewById(R.id.viewUsername);

    if (savedInstanceState != null) {
        bm = savedInstanceState.getParcelable("bm");
        if (bm != null)
            imgCar.setImageBitmap(bm);/*  www. j av a2  s  . c  o m*/
    }

    bar.setVisibility(View.GONE);
    etCarBrand.setVisibility(View.GONE);
    etCarModel.setVisibility(View.GONE);
    viewUsername.setVisibility(carOwnerId == 0 ? View.VISIBLE : View.GONE);

    btnTakePicture.setEnabled(hasCamera);
    btnTakePicture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(ManipulateCarActivity.this)));
            startActivityForResult(intent, CAPTURE_IMAGE);
        }
    });

    btnSaveCar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (validate())
                new SaveCarAsyncTask().execute(SAVECAR_URL);
        }
    });

    spCarBrand.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0)
                ((TextView) parent.getChildAt(position)).setTextColor(Color.GRAY);
            if (mapBrands.get(brands.get(position)) == otherId) {
                etCarBrand.setVisibility(View.VISIBLE);
                etCarModel.setVisibility(View.VISIBLE);
                spCarModel.setVisibility(View.GONE);
                etCarBrand.requestFocus();
            } else {
                etCarBrand.setVisibility(View.GONE);
                etCarModel.setVisibility(View.GONE);
                spCarModel.setVisibility(View.VISIBLE);
                new LoadCarModelsAsyncTask().execute(CARLINE_URL + mapBrands.get(brands.get(position)) + "/");
                reload = true;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spCarModel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0)
                ((TextView) parent.getChildAt(position)).setTextColor(Color.GRAY);
            if (mapModels.get(models.get(position)) == otherId) {
                etCarModel.setVisibility(View.VISIBLE);
                etCarModel.requestFocus();
            } else {
                etCarModel.setVisibility(View.GONE);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    if (useMiniMe) {
        manager = (UsbManager) getSystemService(Context.USB_SERVICE);
        usbCommunication = UsbCommunication.newInstance();

        IntentFilter filter = new IntentFilter();
        filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); // will intercept by system
        filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
        filter.addAction(ACTION_USB_PERMISSION);
        registerReceiver(usbReceiver, filter);

        etEPC = (EditText) findViewById(R.id.etEPC);
        btnReadTAG = (Button) findViewById(R.id.btnReadTAG);
        txtStatus = (TextView) findViewById(R.id.txtStatus);
        btnReadTAG.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                etEPC.setText("");
                if (txtStatus.getText().toString().equals("conectado")) {
                    readTag();
                } else {
                    Toast.makeText(getBaseContext(), "dispositivo " + txtStatus.getText(), Toast.LENGTH_LONG)
                            .show();
                }
            }
        });
    }

    etKM.addTextChangedListener(new NumberTextWatcher(etKM));
}

From source file:com.android.browser.UploadHandler.java

private Intent createCameraIntent(Uri contentUri) {
    if (contentUri == null)
        throw new IllegalArgumentException();
    mCapturedMedia = contentUri;/*from   w w  w .  j  a v  a  2 s. c om*/
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedMedia);
    intent.setClipData(ClipData.newUri(mController.getActivity().getContentResolver(), FILE_PROVIDER_AUTHORITY,
            mCapturedMedia));
    return intent;
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditItem2.java

/**
 * <p>This part of code are copied from the following link:<br>
 * {@link https://github.com/joshua2ua/BogoPicLab}<br>
 * This part is using for taking a picture.</p>
 * /*from  ww w  . jav  a 2s.  c om*/
 * @author Jushua
 */

public void takeAPhoto() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    String folder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp";
    File folderF = new File(folder);
    if (!folderF.exists()) {
        folderF.mkdir();
    }

    String imageFilePath = folder + "/" + String.valueOf(System.currentTimeMillis()) + "jpg";
    File imageFile = new File(imageFilePath);
    imageFileUri = Uri.fromFile(imageFile);

    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

From source file:com.owncloud.android.ui.helpers.FilesUploadHelper.java

/**
 * Function to send an intent to the device's camera to capture a picture
 * *///from  w w  w .ja v  a 2  s.c o m
public void uploadFromCamera(final int requestCode) {
    Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photoFile = createImageFile();
    if (photoFile != null) {
        Uri photoUri = FileProvider.getUriForFile(activity.getApplicationContext(),
                activity.getResources().getString(R.string.file_provider_authority), photoFile);
        pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
    }
    if (pictureIntent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivityForResult(pictureIntent, requestCode);
    }
}

From source file:com.cars.manager.utils.imageChooser.api.ImageChooserManager.java

private String takePicture() throws Exception {
    checkDirectory();// w  w w . ja v a 2s  .co m
    try {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        filePathOriginal = FileUtils.getDirectory(foldername) + File.separator
                + Calendar.getInstance().getTimeInMillis() + ".jpg";
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(filePathOriginal)));
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        throw new Exception("Activity not found");
    }
    return filePathOriginal;
}

From source file:ca.ualberta.app.activity.CreateQuestionActivity.java

/**
 * Create a storage for the picture in the question
 * //from  w  w w .  j  a va  2s  . c o  m
 * @param view
 *            View passed to the activity to check which button was pressed.
 */
public void take_question_pic(View view) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Create a folder to store pictures
    String folder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp";
    File folderF = new File(folder);
    if (!folderF.exists()) {
        folderF.mkdir();
    }

    // Create an URI for the picture file
    String imageFilePath = folder + "/" + String.valueOf(System.currentTimeMillis()) + ".jpg";
    File imageFile = new File(imageFilePath);
    imageFileUri = Uri.fromFile(imageFile);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);

    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

}