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.yanzhenjie.album.util.AlbumUtils.java

/**
 * Start the camera./* w ww .j  a va2s. co  m*/
 *
 * @param activity    activity.
 * @param requestCode code.
 * @param outPath     file path.
 */
public static void startCamera(Activity activity, int requestCode, File outPath) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri uri = getUri(activity, outPath);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    activity.startActivityForResult(intent, requestCode);
}

From source file:com.pdftron.pdf.utils.ViewerUtils.java

public static Uri openImageIntent(Fragment fragment, int requestCode) {
    // Determine Uri of camera image to save.
    final String fname = "IMG_" + System.currentTimeMillis() + ".jpg";
    File sdImageMainDirectory = new File(fragment.getActivity().getExternalCacheDir(), fname);
    Uri outputFileUri = Uri.fromFile(sdImageMainDirectory);

    // Camera.//from www .j  ava2  s  . com
    final List<Intent> cameraIntents = new ArrayList<>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = fragment.getActivity().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(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }

    // Filesystem.
    final Intent galleryIntent = new Intent(Intent.ACTION_PICK);
    galleryIntent.setType("image/*");
    //galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

    fragment.startActivityForResult(chooserIntent, requestCode);
    return outputFileUri;
}

From source file:com.diona.videoplugin.CameraUtil.java

/**
 * Method to get the photo from the camera.
 * /*from w  w  w  .  j  a  v a 2  s . c  o m*/
 * @param fragment
 *          fragment instance that holds the callback method for the camera utility
 */
public static void getPhotoFromCamera(final Fragment fragment) {
    final File imageFile = FileCacheUtil.getOutputMediaFile();
    if (imageFile != null && imageFile.exists()) {
        FileUtils.deleteQuietly(imageFile);
    }
    callingActivity = fragment;
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));

    // start the image capture Intent
    callingActivity.startActivityForResult(intent, CAMERA_REQUEST);
}

From source file:com.commonsware.android.camcon.CameraContentDemoActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (savedInstanceState == null) {
        output = new File(new File(getFilesDir(), PHOTOS), FILENAME);

        if (output.exists()) {
            output.delete();//www . j  ava2s  .  co  m
        } else {
            output.getParentFile().mkdirs();
        }
    } else {
        output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME);
    }

    outputUri = FileProvider.getUriForFile(this, AUTHORITY, output);

    if (savedInstanceState == null) {
        i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri);

            i.setClipData(clip);
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else {
            List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i,
                    PackageManager.MATCH_DEFAULT_ONLY);

            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }

        startActivityForResult(i, CONTENT_REQUEST);
    }
}

From source file:org.alfresco.mobile.android.application.capture.PhotoCapture.java

@Override
public boolean captureData() {
    if (hasDevice()) {
        try {/*  ww  w  .  j  av  a  2s  .c  om*/
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (intent.resolveActivity(context.getPackageManager()) == null) {
                AlfrescoNotificationManager.getInstance(context).showAlertCrouton(parentActivity,
                        context.getString(R.string.feature_disable));
                return false;
            }

            File folder = parentFolder;
            if (folder != null) {
                payload = new File(folder.getPath(), createFilename("IMG_", "jpg"));

                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(payload));

                parentActivity.startActivityForResult(intent, getRequestCode());
            } else {
                AlfrescoNotificationManager.getInstance(parentActivity)
                        .showLongToast(parentActivity.getString(R.string.sdinaccessible));
            }
        } catch (Exception e) {
            Log.d(TAG, Log.getStackTraceString(e));
            return false;
        }

        return true;
    } else {
        return false;
    }
}

From source file:org.telegram.ui.Views.AvatarUpdater.java

public void openCamera() {
    try {//from  w w w.ja  v  a 2 s .  c  o m
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File image = Utilities.generatePicturePath();
        if (image != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
            currentPicturePath = image.getAbsolutePath();
        }
        if (parentFragment != null) {
            parentFragment.startActivityForResult(takePictureIntent, 0);
        } else if (parentActivity != null) {
            parentActivity.startActivityForResult(takePictureIntent, 0);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.javielinux.dialogs.SelectImageDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int title = getArguments().getInt("title");
    idUser = getArguments().getLong("id_user");
    file = getArguments().getString("file");

    return new AlertDialog.Builder(getActivity()).setTitle(title)
            .setItems(R.array.select_type_image, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (which == 0) {
                        File f = new File(file);
                        if (f.exists())
                            f.delete();/*from   ww w  . j a  v a 2s. co  m*/

                        Intent intendCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        intendCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                        intendCapture.putExtra("return-data", true);
                        getActivity().startActivityForResult(intendCapture, ACTIVITY_CAMERA);
                    } else if (which == 1) {
                        Intent i = new Intent(Intent.ACTION_PICK);
                        i.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                                MediaStore.Images.Media.CONTENT_TYPE);
                        getActivity().startActivityForResult(i, ACTIVITY_SELECTIMAGE);
                    }
                }
            }).create();
}

From source file:com.manning.androidhacks.hack035.MainActivity.java

public void onTakePicture(View v) {
    Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Intent chooserIntent = Intent.createChooser(takePhotoIntent,
            getString(R.string.activity_main_pick_picture));
    startActivityForResult(chooserIntent, TAKE_PICTURE);
}

From source file:com.commonsware.android.camcon.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState == null) {
        output = new File(new File(getFilesDir(), PHOTOS), FILENAME);

        if (output.exists()) {
            output.delete();//from  w w  w  .  jav  a 2  s .  co  m
        } else {
            output.getParentFile().mkdirs();
        }

        Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output);

        i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri);

            i.setClipData(clip);
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else {
            List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i,
                    PackageManager.MATCH_DEFAULT_ONLY);

            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }

        try {
            startActivityForResult(i, CONTENT_REQUEST);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, R.string.msg_no_camera, Toast.LENGTH_LONG).show();
            finish();
        }
    } else {
        output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME);
    }
}

From source file:com.qjdchina.qjdsale.MemberPictureFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btn_company_license:
        // ??  sdcard
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (Utils.isHasSdcard()) {
            intent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(new File(SAVE_PATH_IN_SDCARD, IMAGE_CAPTURE_NAME)));
        } else {/* ww w . j  av  a  2 s. c o  m*/
            Toast.makeText(getActivity(), "SD?", Toast.LENGTH_SHORT).show();
        }
        startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);
        break;
    case R.id.iv_comany_license:
        Dialog dialog = new MemberPictureDialog(getActivity(), R.style.dialog_full_screen);
        ImageView iv = (ImageView) dialog.findViewById(R.id.iv_dialog_member);
        iv.setImageBitmap(getImage(SAVE_PATH_IN_SDCARD + IMAGE_CAPTURE_NAME, 1024));
        dialog.show();
        break;
    }
}