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.encontreibvrr.uploadImagem.MainActivityStorage.java

@AfterPermissionGranted(RC_STORAGE_PERMS)
private void launchCamera() {
    Log.d(TAG, "launchCamera");

    // Check that we have permission to read images from external storage.
    String perm = Manifest.permission.WRITE_EXTERNAL_STORAGE;
    if (!EasyPermissions.hasPermissions(this, perm)) {
        EasyPermissions.requestPermissions(this, getString(R.string.rationale_storage), RC_STORAGE_PERMS, perm);
        return;//w  ww  .  j  av  a2  s .  com
    }

    // Choose file storage location, must be listed in res/xml/file_paths.xml
    File dir = new File(Environment.getExternalStorageDirectory() + "/photos");
    File file = new File(dir, UUID.randomUUID().toString() + ".jpg");
    try {
        // Create directory if it does not exist.
        if (!dir.exists()) {
            dir.mkdir();
        }
        boolean created = file.createNewFile();
        Log.d(TAG, "file.createNewFile:" + file.getAbsolutePath() + ":" + created);
    } catch (IOException e) {
        Log.e(TAG, "file.createNewFile" + file.getAbsolutePath() + ":FAILED", e);
    }

    // Create content:// URI for file, required since Android N
    // See: https://developer.android.com/reference/android/support/v4/content/FileProvider.html
    mFileUri = FileProvider.getUriForFile(this, "com.google.firebase.quickstart.firebasestorage.fileprovider",
            file);

    // Create and launch the intent
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);

    startActivityForResult(takePictureIntent, RC_TAKE_PICTURE);
}

From source file:org.apache.cordova.camera.CameraLauncher.java

/**
 * Take a picture with the camera./*from  w  w  w .j  av  a2  s.  c o  m*/
 * When an image is captured or the camera view is cancelled, the result is returned
 * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
 *
 * The image can either be returned as a base64 string or a URI that points to the file.
 * To display base64 string in an img tag, set the source to:
 *      img.src="data:image/jpeg;base64,"+result;
 * or to display URI in an img tag
 *      img.src=result;
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param returnType        Set the type of image to return.
 */
public void takePicture(int returnType, int encodingType) {
    // Save the number of images currently on disk for later
    this.numPics = queryImgDB(whichContentStore()).getCount();

    // Let's use the intent and see what happens
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Specify file so that large image is captured and returned
    File photo = createCaptureFile(encodingType);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    this.imageUri = Uri.fromFile(photo);

    if (this.cordova != null) {
        // Let's check to make sure the camera is actually installed. (Legacy Nexus 7 code)
        PackageManager mPm = this.cordova.getActivity().getPackageManager();
        if (intent.resolveActivity(mPm) != null) {

            this.cordova.startActivityForResult((CordovaPlugin) this, intent,
                    (CAMERA + 1) * 16 + returnType + 1);
        } else {
            LOG.d(LOG_TAG, "Error: You don't have a default camera.  Your device may not be CTS complaint.");
        }
    }
    //        else
    //            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}

From source file:com.getchute.android.photopickerplus.ui.activity.ServicesActivity.java

@Override
public void takePhoto() {
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        NotificationUtil.makeToast(getApplicationContext(), R.string.toast_feature_camera);
        return;//from   w w w .  j  a  v  a2 s .  c  o  m
    }
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        photoFile = AppUtil.getOutputMediaFile(MediaType.IMAGE);
        if (photoFile != null) {
            if (AppUtil.hasImageCaptureBug() == false) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            } else {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            }
            startTheCamera(takePictureIntent, Constants.CAMERA_PIC_REQUEST);
        }
    }
}

From source file:com.khoahuy.phototag.HomeActivity.java

private void dispatchTakePictureIntent(int actionCode) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File f = null;//from  w  w w. j a v  a 2s.  co m
    try {
        f = setUpPhotoFile();
        // mCurrentPhotoPath = f.getAbsolutePath();
        // takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(f));
    } catch (IOException e) {
        e.printStackTrace();
        f = null;
        mCurrentPhotoPath = null;
    }
    switch (actionCode) {
    case ACTION_TAKE_PHOTO_B:
        // takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
        // ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
        break;

    default:
        break;
    } // switch

    startActivityForResult(takePictureIntent, actionCode);
}

From source file:com.collecdoo.fragment.main.RegisterDriverPhotoFragment.java

private void openImageIntent(int uploadIndex) {
    //EasyImage.openChooserWithGallery(this,"Please choose",0);

    File imageFile = ImageHelper.createFile(context, "extend_picture.jpg");
    String cameraImageFullPath = imageFile.getAbsolutePath();
    cameraOutputFileUri = Uri.fromFile(imageFile);

    // Camera.//from ww  w  . j  a  v  a 2  s  . com
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = context.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, cameraOutputFileUri);
        cameraIntents.add(intent);
    }

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

    // 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[] {}));

    startActivityForResult(chooserIntent, uploadIndex);
}

From source file:com.nicefontaine.seanachie.ui.imagestory.ImageStoryFragment.java

private void photo() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        try {/*from  www.j a v a2  s  .  com*/
            File photoFile = FileUtils.createImageFile();
            cacheImagePath(photoFile.getAbsolutePath());
            Uri photoURI = FileProvider.getUriForFile(getActivity(), REPOSITORY, photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            getActivity().startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        } catch (IOException e) {
            Timber.e(e);
        }
    }
}

From source file:com.remobile.camera.CameraLauncher.java

/**
 * Take a picture with the camera./*from   ww w.j a  va 2s  .  c  o  m*/
 * When an image is captured or the camera view is cancelled, the result is returned
 * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
 * <p/>
 * The image can either be returned as a base64 string or a URI that points to the file.
 * To display base64 string in an img tag, set the source to:
 * img.src="data:image/jpeg;base64,"+result;
 * or to display URI in an img tag
 * img.src=result;
 *
 * @param quality    Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param returnType Set the type of image to return.
 */
public void takePicture(int returnType, int encodingType) {
    // Save the number of images currently on disk for later
    this.numPics = queryImgDB(whichContentStore()).getCount();

    // Let's use the intent and see what happens
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Specify file so that large image is captured and returned
    File photo = createCaptureFile(encodingType);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    this.imageUri = Uri.fromFile(photo);

    if (this.cordova != null) {
        // Let's check to make sure the camera is actually installed. (Legacy Nexus 7 code)
        PackageManager mPm = this.cordova.getActivity().getPackageManager();
        if (intent.resolveActivity(mPm) != null) {

            this.cordova.startActivityForResult((CordovaPlugin) this, intent,
                    (CAMERA + 1) * 16 + returnType + 1);
        } else {
            FLog.d(LOG_TAG, "Error: You don't have a default camera.  Your device may not be CTS complaint.");
        }
    }
    //        else
    //            FLog.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}

From source file:de.wikilab.android.friendica01.HomeActivity.java

void navigate(String arg1) {
    currentMMItem = arg1;/*from  w  w w .  ja v  a 2  s .co  m*/

    if (arg1.equals("Timeline")) {
        navigatePostList("timeline");
    }

    if (arg1.equals("Notifications")) {
        navigatePostList("notifications");
    }

    if (arg1.equals("My Wall")) {
        navigatePostList("mywall");
    }

    if (arg1.equals("Update My Status")) {
        navigateStatusUpdate();
    }

    if (arg1.equals("Friends")) {
        navigateFriendList();
    }

    if (arg1.equals("My Photo Albums")) {
        navigatePhotoGallery("myalbums");
    }

    if (arg1.equals("Take Photo And Upload")) {
        Intent in = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        takePhotoTarget = Max.getTempFile();
        in.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(takePhotoTarget));
        startActivityForResult(in, RQ_TAKE_PHOTO);
    }
    if (arg1.equals("Select Photo And Upload")) {
        Intent in = new Intent(Intent.ACTION_PICK);
        in.setType("image/*");
        startActivityForResult(in, RQ_SELECT_PHOTO);
    }
    if (arg1.equals("Messages")) {
        //Intent in = new Intent(HomeActivity.this, MessagesActivity.class);
        //startActivity(in);
        navigateMessages("msg:all");
    }

    if (arg1.equals("Preferences")) {
        navigatePreferences();
    }

    if (arg1.equals("Log Out")) {
        SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(HomeActivity.this)
                .edit();
        //prefs.putString("login_server", null); //keep server and user ...
        prefs.putString("login_user", null);
        prefs.putString("login_password", null); //...only remove password
        prefs.commit();

        finish();
    }

}

From source file:foam.starwisp.StarwispBuilder.java

public static void photo(StarwispActivity ctx, String path, int code) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(ctx.getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;//from   w w w.java 2  s  . c  o m
        photoFile = new File(path);

        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            ctx.startActivityForResult(takePictureIntent, code);
        } else {
            Log.i("starwisp", "Could not open photo file");
        }
    }
}

From source file:io.mapsquare.osmcontributor.ui.activities.PhotoActivity.java

private void takePicture() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        try {//from  www  . j  a v  a2s.  c  om
            photoFile = createImageFile();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this, "io.mapsquare.osmcontributor.fileprovider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_CAMERA);
        }
    }
}