Try the following:
// Photo intent. Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); intent.setType("image/*"); // Intent parameters. intent.putExtra("crop", "true"); intent.putExtra("aspectX", 30); // This sets the max width. intent.putExtra("aspectY", 30); // This sets the max height. intent.putExtra("outputX", 1); intent.putExtra("outputY", 1); intent.putExtra("scale", true); intent.putExtra("return-data", true); intent.putExtra(MediaStore.EXTRA_OUTPUT, newImageFile()); intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); // Send intent. activity.startActivityForResult(intent, BibleActivity.CROP_PHOTO_REQUEST_CODE);
To get a new image file:
/** * Create new temporary file for cropped image. * @return uri */ public Uri newImageFile() { return Uri.fromFile(createFile(CROPPED_FILENAME)); } /** * Create file. * @return file. */ private File createFile(String fileName) { // Make sure we have SD Card. if (isSDCARDMounted()) { // File location. File file = new File(activity.getExternalFilesDir(null), fileName); try { // Delete if exist. if (file.exists()) file.delete(); // Create new file. file.createNewFile(); } catch (IOException e) { Toast.makeText(activity, R.string.error_cannot_create_temp_file, Toast.LENGTH_LONG).show(); } return file; } else { Toast.makeText(activity, R.string.error_no_sd_card_present, Toast.LENGTH_LONG).show(); return null; } } /** * Check to make sure we have SD Card. * @return */ private boolean isSDCARDMounted() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) return true; else return false; }
source share