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.kinvey.samples.statusshare.StatusShare.java

public void startCamera() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Environment.getExternalStorageDirectory(),
            "tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
    mImageCaptureUri = Uri.fromFile(file);

    try {//w  w w . j av a 2  s.com
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
        intent.putExtra("return-data", true);

        startActivityForResult(intent, PICK_FROM_CAMERA);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:de.skubware.opentraining.activity.create_exercise.ImageFragment.java

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        try {/*from  ww w . jav a  2s . c  o  m*/
            mTempImageUri = createImageFile(false);
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.e(TAG, "Error creating image file", ex);
        }
        takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mTempImageUri);
        startActivityForResult(takePictureIntent, CreateExerciseActivity.TAKE_PICTURE);
    } else {
        Log.e(TAG, "No camera activity for handling camera intent");
    }
}

From source file:com.akalizakeza.apps.ishusho.activity.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;/*from   w  w w .j ava  2  s  . c om*/
    }

    // 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, getString(R.string.picture_chooser_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
    startActivityForResult(chooserIntent, TC_PICK_IMAGE);
}

From source file:com.dexin.MainActivity.java

public void startCamera() {
    if (PermissionUtils.requestPermission(this, CAMERA_PERMISSIONS_REQUEST,
            Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri photoUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider",
                getCameraFile());//from  w  ww  .  jav  a2s  . c  o  m
        intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivityForResult(intent, CAMERA_IMAGE_REQUEST);
    }
}

From source file:br.com.brolam.cloudvision.ui.helpers.ImagesHelper.java

/**
 * Realizar uma requisio de uma foto na camera fotogrfica nativa do Android para uma imagem
 * de background Note Vision.//from  w  w  w.  j  a  va  2s .  com
 * @param noteVisionKey informar uma chave vlida.
 * @throws IOException
 */
public void takeNoteVisionBackground(String noteVisionKey) throws IOException {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
        //Informar o arquivo temporrio onde a imagem ser gravada.
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUriFileProvider(noteVisionKey));
        //Informar a chave do Note Vision que ser recuperado no mtodo {@see saveNoteVisionBackground}
        requestImageNoteVisionKey = noteVisionKey;
        activity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
}

From source file:com.app.imagecreator.activities.HomeActivity.java

private void loadFromCamera() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    ContentValues contentValues = new ContentValues();
    outputFileUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

    startActivityForResult(intent, FETCH_FROM_CAMERA_FULLVIEW);

}

From source file:com.intel.xdk.camera.Camera.java

public synchronized void takePicture(final int quality, final String saveToLibYN, final String picType) {
    //saveToLibYN is not used because the camera activity always saves to gallery

    PackageManager pm = activity.getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) == false) {
        fireJSEvent("camera.picture.add", false, null,
                new String[] { String.format("ev.error='device has no camera';") });
    }/*from www .j  ava2s.c o m*/

    if (busy) {
        cameraBusy();
    }
    this.busy = true;

    File outputFile = new File(Environment.getExternalStorageDirectory(), "test." + picType);

    //put required info in shared prefs
    SharedPreferences.Editor prefsEditor = activity.getSharedPreferences(cameraPrefsKey, 0).edit();
    prefsEditor.putString(cameraPrefsFileName, outputFile.getAbsolutePath());
    prefsEditor.putBoolean(cameraPrefsIsPNG, "png".equalsIgnoreCase(picType));
    prefsEditor.putInt(cameraPrefsQuality, quality);
    prefsEditor.commit();

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outputFile));

    //cordova.setActivityResultCallback(this);
    // TODO: figure this out
    cordova.startActivityForResult(this, intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    //activity.setLaunchedChildActivity(true);
    //activity.startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

From source file:com.guanyin.userface.ViewPagerActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.iv_oil:
        catchStation();/*from   www.j  ava2s .  c o  m*/
        break;
    case R.id.tv_logout:
        LayoutInflater inflater = LayoutInflater.from(this);
        final View loginView = inflater.inflate(R.layout.logout_dialog, null);
        AlertDialog.Builder loginBuilder = new AlertDialog.Builder(this);
        loginBuilder.setView(loginView);

        loginBuilder.setPositiveButton("", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Editor editor = app.sp.edit();
                editor.putString("token", "");
                editor.apply();
                intent = new Intent(context, LoginActivity.class);
                startActivity(intent);
                finish();
            }

        });
        loginBuilder.setNegativeButton("?", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ViewPagerActivity.this.dialog.dismiss();
            }

        });

        dialog = loginBuilder.create();
        dialog.show();
        break;
    case R.id.rb_main:
        viewPager.setCurrentItem(0, true);
        break;
    case R.id.rb_carb:
        viewPager.setCurrentItem(1, true);
        break;
    case R.id.rb_photo:
        intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivity(intent);
        break;
    case R.id.rb_iphone:
        intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:" + "18829282408"));
        startActivity(intent);
        break;
    default:
        break;
    }
}

From source file:com.renard.ocr.BaseDocumentActivitiy.java

protected void startCamera() {
    try {//  w w w .  jav  a  2 s.  c o m
        cameraPicUri = null;
        dateCameraIntentStarted = new Date();
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";

        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        File image = null;
        try {
            if (!storageDir.exists()) {
                storageDir.mkdirs();
            }
            image = new File(storageDir, imageFileName + ".jpg");
            if (image.exists()) {
                image.createNewFile();
            }
            cameraPicUri = Uri.fromFile(image);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, cameraPicUri);
            startActivityForResult(intent, REQUEST_CODE_MAKE_PHOTO);
        } catch (IOException e) {
            showFileError(PixLoadStatus.IO_ERROR);
        }

    } catch (ActivityNotFoundException e) {
        showFileError(PixLoadStatus.CAMERA_APP_NOT_FOUND);
    }
}

From source file:com.business.rushour.businessapp.TabOwnerRegistrationActivity.java

public void captureImage(View view) {
    final CharSequence[] options = { "Take Photo", "Choose from Gallery", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
    builder.setTitle("Add Photo!");

    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override//from w  ww.ja va 2s.  c o m
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
                try {
                    final Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    //startActivityForResult(cameraIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
                    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

                    // start the image capture Intent
                    startActivityForResult(cameraIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
                }

                catch (ActivityNotFoundException anfe) {
                    String errorMessage = "Whoops - your device doesn't support capturing images!";
                    //Toast toast = Toast.makeText(view.getContext(), errorMessage, Toast.LENGTH_SHORT);
                    //toast.show();
                }
            }

            else if (options[item].equals("Choose from Gallery")) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);

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