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.bai.android.ui.OtherActivity.java

public void changeAvatar() {
    // Prompt the user to select image from gallery or camera.
    alertDialog = new AlertDialog.Builder(OtherActivity.this);
    alertDialog.setMessage(getResources().getString(R.string.select_image_source));

    alertDialog.setPositiveButton(getResources().getString(R.string.gallery),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // remove the dialog to prevent "leakage"
                    dialog.dismiss();/*from   w  w  w . jav  a  2 s  . c  om*/

                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
                    intent.setType("image/*");

                    startActivityForResult(intent, GALLERY_IMAGE_ACTIVITY_REQUEST_CODE);
                }
            });

    alertDialog.setNeutralButton(getResources().getString(R.string.camera),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Uri imageUri = getOutputMediaFileUri(); // create a file to save the image 
                    if (imageUri != null) {
                        SharedPreferences.Editor prefEditor = getSharedPreferences(SHR_PRF_APP_KEY,
                                MODE_PRIVATE).edit();
                        prefEditor.putString(SHR_PRF_IMG_URI, imageUri.getPath());
                        prefEditor.commit();
                        prefEditor = null;
                        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); // set the image file name

                        // start the image capture Intent
                        startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
                    }

                }

            });

    alertDialog.setNegativeButton(getResources().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // close this dialog
                    dialog.dismiss();
                }
            });

    alertDialog.show();

}

From source file:com.grass.caishi.cc.activity.SettingUserActivity.java

/**
 * ?/*w  w  w. j a  v  a 2s .c  o m*/
 */
public void selectPicFromCamera() {

    // cameraFile = new File(PathUtil.getInstance().getImagePath(),
    // DemoApplication.getInstance().getUserName()

    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), USERPIC_REQUEST_CODE_CAMERA);
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Insurance.AddDriver.java

private void cameraIntent() {
    if (btnClicked == UtilityBillsButton) {

        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_UtilityBills);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_UtilityBills);
    } else if (btnClicked == BaseLetterButton) {

        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_BaseLetter);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_BaseLetter);
    } else if (btnClicked == DriverLicenseButton) {

        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_DriverLicensebtn);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_DriverLicensebtn);
    } else if (btnClicked == TlcLicenseButton) {

        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_TlcLicensebtn);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_TlcLicensebtn);
    }/*from  ww w .j ava2 s . c  o  m*/

}

From source file:com.mobantica.DriverItRide.activities.ActivityProfile.java

private void selectImage() {
    final CharSequence[] options = { getResources().getString(R.string.take_photo),
            getResources().getString(R.string.select_from_gallery), getResources().getString(R.string.cancel) };
    android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);

    builder.setTitle(getResources().getString(R.string.add_photo));

    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override/*ww  w  . ja  v a 2s .  com*/
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals(getResources().getString(R.string.take_photo))) {
                Boolean isSDPresent = android.os.Environment.getExternalStorageState()
                        .equals(android.os.Environment.MEDIA_MOUNTED);
                if (isSDPresent) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
                    startActivityForResult(intent, 1);
                    //Log.d(TAG, "onClick: " + fileUri);
                    ChnagedUri = fileUri;
                } else {
                    myToast(ActivityProfile.this,
                            getResources().getString(R.string.insert_an_sd_card_before_using_the_camera));
                }
            } else if (options[item].equals(getResources().getString(R.string.select_from_gallery))) {
                Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, 2);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }

    });

    builder.show();
}

From source file:com.xxjwd.chat.ChatActivity.java

 /**
 * ?/*  w  ww .  j  a  v a2 s . c  o  m*/
 */
public void selectPicFromCamera() {
   if (!CommonUtils.isExitsSdcard()) {
      Toast.makeText(getApplicationContext(), "SD????", 0).show();
      return;
   }

   cameraFile = new File(ChatFileUtil.getInstance(this).getChatFilePath(FileType.Picture), 
          System.currentTimeMillis() + ".jpg");
   cameraFile.getParentFile().mkdirs();
   startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)),
         REQUEST_CODE_CAMERA);
}

From source file:com.tt.jobtracker.MainActivity.java

public void onTaskLineItemShopPhoto(TaskViewModel taskViewModel) {
    tvm = taskViewModel;/*  w w w.ja v  a  2  s.  co  m*/
    tlvm = taskLineItemViewModel;
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    fileUri = CameraHelper.getOutputMediaFileUri(CameraHelper.MEDIA_TYPE_IMAGE); // create
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the
    startActivityForResult(intent, CAPTURE_TASKLINEITEM_SHOP_IMAGE_ACTIVITY_REQUEST_CODE);
}

From source file:com.ereinecke.eatsafe.MainActivity.java

private void launchPhotoIntent(int whichPhoto) {

    Logd(LOG_TAG, "Launching intent for photo #" + whichPhoto);
    // create Intent to take a picture and return control to the calling application
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

        // Create the File where the photo should go
        File photoFile = openOutputMediaFile();
        Logd(LOG_TAG, "photoReceived: " + photoReceived);

        if (photoFile != null) {

            Uri photoUri = StreamProvider.getUriForFile("com.ereinecke.eatsafe.fileprovider", photoFile);
            try {
                Logd(LOG_TAG, "photoUri: " + photoUri.toString());
            } catch (Exception e) {
                Logd(LOG_TAG, "photoUri is null: " + e.getMessage());
            }/*from   w w  w . j  ava2s.c o m*/
            // set the image file name
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
            takePictureIntent.putExtra(Constants.WHICH_PHOTO, whichPhoto);
            takePictureIntent
                    .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

            // start the image capture Intent
            startActivityForResult(takePictureIntent, Constants.CAMERA_IMAGE_REQUEST);
        }
    }
}

From source file:com.easemob.ui.ChatActivity.java

/**
 * ?/* www. j a v a2 s .  c  o m*/
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        Toast.makeText(getApplicationContext(), "SD????", 0).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            MyApplication.getInstance().getUserName() + System.currentTimeMillis() + ".jpg");
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}

From source file:com.ximai.savingsmore.save.activity.BusinessMyCenterActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (resultCode != RESULT_OK) {
        return;// ww w.j av  a 2 s . com
    } else if (requestCode == PICK_FROM_CAMERA || requestCode == PICK_FROM_IMAGE) {

        Uri uri = null;
        if (null != intent && intent.getData() != null) {
            uri = intent.getData();
        } else {
            String fileName = PreferencesUtils.getString(this, "tempName");
            uri = Uri.fromFile(new File(FileSystem.getCachesDir(this, true).getAbsolutePath(), fileName));
        }

        if (uri != null) {
            cropImage(uri, CROP_PHOTO_CODE);
        }
    } else if (requestCode == CROP_PHOTO_CODE) {
        Uri photoUri = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
        if (isslinece) {
            MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), slience_image);
            zhizhao_path = photoUri.toString();
            try {
                upLoadImage(new File((new URI(photoUri.toString()))), "BusinessLicense");
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        } else if (isZhengshu) {
            MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), zhengshu_iamge);
            xukezheng_path = photoUri.toString();
            try {
                upLoadImage(new File((new URI(photoUri.toString()))), "LicenseKey");
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        } else if (isheadImage) {
            MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), head_image);
            tuoxiang_path = photoUri.toString();
            try {
                upLoadImage(new File((new URI(photoUri.toString()))), "Photo");
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            //upLoadImage(new File((new URI(photoUri.toString()))), "Photo");
        } else if (isItem) {
            if (imagePath.size() + images.size() < 10) {
                shangpu_path.add(photoUri.toString());
                try {
                    upLoadImage(new File((new URI(photoUri.toString()))), "Seller");
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
                //imagePath.add(photoUri.getPath());
            } else {
                Toast.makeText(BusinessMyCenterActivity.this, "?9",
                        Toast.LENGTH_SHORT).show();
            }
        }
        //addImage(imagePath);
    }
}

From source file:com.imalu.alyou.activity.ChatActivity.java

/**
 * ?/*from  w w  w  .ja v  a2 s . co m*/
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        Toast.makeText(getApplicationContext(), "SD????", 0).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            AlUApplication.getInstance().getUserName() + System.currentTimeMillis() + ".jpg");
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}