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

/**
 * Start the camera.//w w w. ja v  a 2 s. com
 *
 * @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:de.baumann.quitsmoking.helper.Popup_camera.java

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

    Toast.makeText(Popup_camera.this, R.string.cam_start, Toast.LENGTH_LONG).show();

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File f = helper_main.newFile();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Uri contentUri = FileProvider.getUriForFile(Popup_camera.this,
                getApplicationContext().getPackageName() + ".provider", f);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
    } else {/*w  w  w. j  a  va2 s  .c o m*/
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
    }

    try {
        startActivityForResult(intent, 1);
        finish();
    } catch (ActivityNotFoundException e) {
        Toast.makeText(Popup_camera.this, R.string.cam_fail, Toast.LENGTH_SHORT).show();
    }
}

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

/**
 * Method to get the photo from the camera.
 * /*from  www  .j  ava  2 s  .  co 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.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();//w w w  . java2 s.c o  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.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./*  w  w  w  .  ja  va  2 s  .  c o m*/
    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.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();/*  w  w  w  . j  a  v a2 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.netease.hearttouch.htimagepicker.core.camera.HTCameraActivity.java

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

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    HTBaseCameraFragment fragment = null;
    try {//from   w w  w  .j a  v  a2 s .  c  o  m
        Class fragmentClazz = HTImagePicker.INSTANCE.getUIConfig().getCameraFragmentClazz();
        Constructor<HTBaseCameraFragment> fragmentConstructor = fragmentClazz.getConstructor();
        fragment = fragmentConstructor.newInstance();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }

    // ?
    if (fragment == null) {
        finish(null);
        return;
    }

    Uri photoPath = getIntent().getParcelableExtra(MediaStore.EXTRA_OUTPUT);
    if (photoPath != null) {
        Bundle bundle = new Bundle();
        bundle.putParcelable(MediaStore.EXTRA_OUTPUT, photoPath);
        fragment.setArguments(bundle);
    }

    fragmentTransaction.add(android.R.id.content, fragment);
    fragmentTransaction.commit();
}

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

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

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

        if (output.exists()) {
            output.delete();/*ww  w  .  j a  v a  2s .c om*/
        } else {
            output.getParentFile().mkdirs();
        }
    } else {
        output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME);
    }

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

    if (savedInstanceState == null) {
        Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

        i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
        i.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_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 | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
        }

        startActivityForResult(i, REQUEST_ID);
    }
}

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();/*from   w ww. j a v  a2 s  .c  om*/
        } 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: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 {//from  ww  w.  ja v 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;
    }
}