Example usage for android.provider MediaStore EXTRA_OUTPUT

List of usage examples for android.provider MediaStore EXTRA_OUTPUT

Introduction

In this page you can find the example usage for android.provider MediaStore EXTRA_OUTPUT.

Prototype

String EXTRA_OUTPUT

To view the source code for android.provider MediaStore EXTRA_OUTPUT.

Click Source Link

Document

The name of the Intent-extra used to indicate a content resolver Uri to be used to store the requested image or video.

Usage

From source file:Main.java

public static void getCameraFromSelfCenter(Activity activity, boolean openFrontCamera) {
    initData(activity);/*from   ww  w. j  av a2s .  c  o m*/
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    Intent intent_camera = activity.getPackageManager().getLaunchIntentForPackage("com.android.camera");
    if (intent_camera != null) {
        intent.setPackage("com.android.camera");
    }
    if (openFrontCamera) {
        intent.putExtra("android.intent.extras.CAMERA_FACING", 1);
    }
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mAvatarUri);
    activity.startActivityForResult(intent, REQUEST_TAKE_PICTURE_SELF_CENTER);
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static Uri launchActivityForResult(Activity activity, Intent intent, int requestCode) {
    SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
    String filename = timeStampFormat.format(new Date());
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, filename);
    Uri photoUri = activity.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
    activity.startActivityForResult(intent, requestCode);
    return photoUri;
}

From source file:Main.java

public static void cropImgFromSelfCenter(Uri uri) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 110);
    intent.putExtra("aspectY", 135);
    intent.putExtra("outputX", 110);
    intent.putExtra("outputY", 135);
    intent.putExtra("return-data", false);
    intent.putExtra("noFaceDetection", true);
    File mFile = new File(Environment.getExternalStorageDirectory() + "/yourName");
    if (!mFile.exists())
        mFile.mkdirs();/*from w  ww.  j a  va2 s  .c o m*/
    mCropAvatar = new File(CROP_IMG_PATH);
    if (mCropAvatar.exists())
        mCropAvatar.delete();
    mCropUri = Uri.fromFile(mCropAvatar);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mCropUri);
    mActivity.startActivityForResult(intent, REQUEST_CROP_RETURN_SELF_CENTER);
}

From source file:com.netease.hearttouch.htimagepicker.core.camera.HTCameraActivity.java

public static void startForResult(Activity activity, Uri outputFile, int requestId) {
    Intent intent = new Intent(activity, HTCameraActivity.class);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFile);
    activity.startActivityForResult(intent, requestId);
}

From source file:com.yanzhenjie.album.util.AlbumUtils.java

/**
 * Start the camera./*from   ww  w  .  j  a  v a 2 s  . com*/
 *
 * @param fragment    fragment.
 * @param requestCode code.
 * @param outPath     file path.
 */
public static void startCamera(Fragment fragment, int requestCode, File outPath) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri uri = getUri(fragment.getContext(), outPath);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    fragment.startActivityForResult(intent, requestCode);
}

From source file:Main.java

public static List<Intent> createTakePictureIntentList(@NonNull Context context, @NonNull Uri outputFileUri) {
    List<Intent> cameraIntents = new ArrayList<>();
    Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        String packageName = res.activityInfo.packageName;
        Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);//ww w.j a  v  a2 s . co  m
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }

    return cameraIntents;
}

From source file:Main.java

public static Intent getImageFromGalleryCamera(Context context) {
    // Determine Uri of camera image to save.
    File root = new File(
            Environment.getExternalStorageDirectory() + File.separator + "dianta/camera" + File.separator);
    root.mkdirs();/* w  w w  .  j  a v  a2  s.  c  o m*/
    String fname = "dianta-" + System.currentTimeMillis() + ".jpg";
    File sdImageMainDirectory = new File(root, fname);
    Uri outputFileUri = Uri.fromFile(sdImageMainDirectory);

    // camera
    List<Intent> cameraIntents = new ArrayList<>();
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager lPackageManager = context.getPackageManager();
    List<ResolveInfo> listCam = lPackageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo rInfo : listCam) {
        String packageName = rInfo.activityInfo.packageName;
        Intent lIntent = new Intent(captureIntent);
        lIntent.setComponent(new ComponentName(rInfo.activityInfo.packageName, rInfo.activityInfo.name));
        lIntent.setPackage(packageName);
        //save camera result to external storage
        lIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(lIntent);
    }

    //ugly hacks for camera helper
    lastCameraImageSaved = outputFileUri;

    // gallery
    Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_PICK);

    Intent chooserIntent = Intent.createChooser(galleryIntent, "Pilih Sumber");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));

    return chooserIntent;
}

From source file:com.yanzhenjie.album.util.AlbumUtils.java

/**
 * Start the camera.//w  w  w  .j a va  2  s .c om
 *
 * @param fragment    fragment.
 * @param requestCode code.
 * @param outPath     file path.
 */
public static void startCamera(android.app.Fragment fragment, int requestCode, File outPath) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri uri = getUri(fragment.getActivity(), outPath);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    fragment.startActivityForResult(intent, requestCode);
}

From source file:MainActivity.java

public void takePicture(View view) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        mLastPhotoURI = createFileURI();
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mLastPhotoURI);
        startActivityForResult(takePictureIntent, PHOTO_RESULT);
    }// ww w .j  a  v a2s.  co  m
}

From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java

public static void showPictureLauncher(final Activity activity, final ClearImageCallback clearImageOption) {
    ArrayList<String> options = new ArrayList<String>();

    final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager pm = activity.getPackageManager();

    final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0;
    if (cameraAvailable)
        options.add(activity.getString(R.string.actfm_picture_camera));
    options.add(activity.getString(R.string.actfm_picture_gallery));

    if (clearImageOption != null)
        options.add(activity.getString(R.string.actfm_picture_clear));

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()]));

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @SuppressWarnings("nls")
        @Override/* w  w  w.  jav a 2 s .  c  om*/
        public void onClick(DialogInterface d, int which) {
            if (which == 0 && cameraAvailable) {
                lastTempFile = getTempFile(activity);
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (lastTempFile != null) {
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile));
                }
                activity.startActivityForResult(intent, REQUEST_CODE_CAMERA);
            } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                activity.startActivityForResult(
                        Intent.createChooser(intent, activity.getString(R.string.actfm_TVA_tag_picture)),
                        REQUEST_CODE_PICTURE);
            } else {
                if (clearImageOption != null)
                    clearImageOption.clearImage();
            }
        }
    };

    // show a menu of available options
    new AlertDialog.Builder(activity).setAdapter(adapter, listener).show().setOwnerActivity(activity);
}