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.app.ecofriend.ecofriend.DisplayMessageActivity.java

private void takePicture() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photo = new File(Environment.getExternalStorageDirectory(), "picture.jpg");
    imageUri = Uri.fromFile(photo);/*www .  ja  v  a2s.  c om*/
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(intent, PHOTO_REQUEST);
}

From source file:com.google.android.apps.forscience.whistlepunk.PictureUtils.java

private static String capturePictureLabel(Context context, IStartable startable) {
    // Starts a picture intent.
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) {
        File photoFile = null;/*from  w w w . j  av a2s . co  m*/
        try {
            photoFile = PictureUtils.createImageFile(
                    AppSingleton.getInstance(context).getSensorEnvironment().getDefaultClock().getNow());
        } catch (IOException ex) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, ex.getMessage());
            }
        }
        if (photoFile != null) {
            Uri photoUri = FileProvider.getUriForFile(context, context.getPackageName(), photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                // Needed to avoid security exception on KitKat.
                takePictureIntent.setClipData(ClipData.newRawUri(null, photoUri));
            }
            takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            String pictureLabelPath = "file:" + photoFile.getAbsoluteFile();
            startable.startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
            return pictureLabelPath;
        }
    }
    return null;
}

From source file:com.semfapp.adamdilger.semf.hazardIdF5.java

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

    // Create the File where the photo should go
    File photoFile = null;//from  w  ww . j  ava 2s  . c  o  m
    try {
        photoFile = data.createImageFile();
        imageFileCurrentPath = photoFile.getPath();
    } catch (Exception ex) {
        Toast.makeText(getActivity().getApplicationContext(), "Error: " + ex.toString(), Toast.LENGTH_LONG)
                .show();
        System.out.println(ex.toString());
    }
    // Continue only if the File was successfully created
    if (photoFile != null) {
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
}

From source file:io.hypertrack.sendeta.util.images.EasyImage.java

private static Intent createChooserIntent(Context context, String chooserTitle, boolean showGallery)
        throws IOException {
    Uri outputFileUri = createCameraPictureFile(context);
    List<Intent> cameraIntents = new ArrayList<>();
    Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> camList = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : camList) {
        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);// w  w w . j  a v a 2 s. c o  m
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }
    Intent galleryIntent;

    if (showGallery) {
        galleryIntent = createGalleryIntent();
    } else {
        galleryIntent = createDocumentsIntent();
    }

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

    return chooserIntent;
}

From source file:arun.com.chameleonskinforkwlp.activities.CameraCapturerActivity.java

private void launchCamera() {
    final Intent capturePicIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Check if any app can handle this intent for us.
    final ComponentName componentName = capturePicIntent.resolveActivity(getPackageManager());
    if (componentName != null) {
        File imageFile = null;/*  w w w .j a v  a2  s. c om*/
        try {
            imageFile = createTemporaryFile();
        } catch (IOException ex) {
            Timber.e("Error while creating image file", ex);
        }
        if (imageFile != null) {
            final Uri photoURI = FileProvider.getUriForFile(this, "arun.com.chameleonskinforkwlp.fileprovider",
                    imageFile);
            capturePicIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(capturePicIntent, REQUEST_IMAGE_CAPTURE);
        } else {
            onCameraLaunchingFailed();
        }
    } else {
        onNoCameraDetected();
    }
}

From source file:com.semfapp.adamdilger.semf.SiteInstructionF3.java

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

    // Create the File where the photo should go
    File photoFile = null;//from  w ww .j  av a  2 s.c  o m
    try {
        photoFile = data.createImageFile();
        imageFileCurrentPath = photoFile.getPath();
    } catch (Exception ex) {
        Toast.makeText(getActivity(), "Error: " + ex.toString(), Toast.LENGTH_LONG).show();
        System.out.println(ex.toString());
    }
    // Continue only if the File was successfully created
    if (photoFile != null) {
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
}

From source file:mysteryinc.eagleeye.LiveLocatorFragment.java

/**
 * Start the camera by dispatching a camera intent. Returns a string location to the photo.
 *///from  w w  w. j  a v a2 s . c  om
private String takePicture() {
    // Check if there is a camera.
    if (deviceMissingCamera()) {
        MainActivity.toast("This device does not have a camera.");
        return "";
    }

    // Camera exists? Then proceed...
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Ensure that there's a camera activity to handle the intent
    Activity activity = getActivity();
    File photoFile = null;
    if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
        // Create the File where the photo should go.
        // If you don't do this, you may get a crash in some devices.
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            ex.printStackTrace();
            MainActivity.toast("There was a problem saving the photo...");
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri fileUri = Uri.fromFile(photoFile);
            //                activity.setCapturedImageURI(fileUri);
            //                activity.setCurrentPhotoPath(fileUri.getPath());
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
            //                        activity.getCapturedImageURI());
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
    return photoFile.getAbsolutePath();
}

From source file:com.zhongsou.souyue.ui.webview.CustomWebChromeClient.java

/**
 * /*from ww  w  .  j  a v a  2s .  c  o m*/
 */
private void openCarcme() {
    try {
        imageFileUri = mContext.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                new ContentValues());
        if (imageFileUri != null) {
            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
            if (Utils.isIntentSafe(mContext, i)) {
                fragment.startActivityForResult(i, REQ_CAMERA);
            } else {
                Toast.makeText(mContext, "", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(mContext, "", Toast.LENGTH_SHORT).show();
        }
    } catch (Exception e) {
        Toast.makeText(mContext, "", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.king.base.util.SystemUtils.java

/**
 * ?//from w ww.  j  a  v  a 2 s  .  c om
 *
 * @param activity
 * @param path
 * @param requestCode
 */
public static void imageCapture(Activity activity, String path, int requestCode) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (!TextUtils.isEmpty(path)) {
        Uri uri = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(activity, activity.getPackageName() + ".fileProvider",
                    new File(path));
        } else {
            uri = Uri.fromFile(new File(path));
        }
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    }
    activity.startActivityForResult(intent, requestCode);
}

From source file:com.univpm.s1055802.faceplusplustester.Detect.AcquirePhoto.java

/**
 * Richiama la fotocamera, acquisisce la foto e la salva in un file
 * @return il file salvato//from w w w  . j  a v  a 2  s  .c o m
 */
private void Acquire() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    photoFile = null;
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go

        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.v("alert", "file error");
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}