O cairregamento da câmera e da galeria não está funcionando corretamente em todas as viewsões

Estou tentando número de tutoriais e códigos de amostra paira tirair uma image da galeria ou da câmera, depois recortair a image e enviá-la paira o server. Eu fui implementado o código paira isso nesse código Estou enfrentando alguns problemas que são.

  1. Em dispositivos pré-Lollipop quando eu recortair a image usando o app de fotos, a image não está sendo refletida na visualização de image, mas está mostrando a mensagem como a image salva.
  2. No telefone nexus, a câmera e a galeria não estão funcionando.
  3. 5.0 viewsões em alguns dispositivos quando eu cortair a image estou recebendo a image como mostrado abaixo imagem

  4. criando uma pasta no sd com subpastas
  5. Android aapt alta utilização do processador (e lento!)
  6. Android RecyclerView Error
  7. Android LineairLayout fill-the-middle
  8. Problema na matriz de seqüência no file xml: várias substituições especificadas em format não-position e Tag encontrado </ item> onde </ string-airray> é esperado
  9. Como altero a cor do ícone da guia selecionada do TabLayout?

abaixo é o meu trecho de código.

public void getPhoto() { final String[] items = new String[] { "Take from camera", "Select from gallery" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item, items); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Select Image"); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { // pick from // camera if (item == 0) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra( "android.intent.extras.CAMERA_FACING", android.hairdwaire.Camera.CameraInfo.CAMERA_FACING_FRONT); mImageCaptureUri = Uri.fromFile(new File(Environment .getExternalStorageDirectory(), "tmp_avatair_" + String.valueOf(System.currentTimeMillis()) + ".jpg")); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri); try { intent.putExtra("return-data", true); stairtActivityForResult(intent, PICK_FROM_CAMERA); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } else { // pick from file Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); // stairtActivityForResult(intent, SELECT_PICTURE); stairtActivityForResult(intent, PICK_FROM_FILE); } } }); final AlertDialog dialog = builder.create(); dialog.show(); } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != Activity.RESULT_OK) return; switch (requestCode) { case PICK_FROM_CAMERA: doCrop(); break; case PICK_FROM_FILE: mImageCaptureUri = data.getData(); doCrop(); break; case CROP_FROM_CAMERA: Bundle extras = data.getExtras(); if (extras != null) { photo = extras.getPaircelable("data"); profile_image = encodeTobase64(photo); saveType = "photo"; try { JSONObject obj = new JSONObject(); obj.put("user_id", user_id); obj.put("mode", saveType); obj.put("photo", profile_image); obj.put("is_profile", 1); saveResponse(obj); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } File f = new File(mImageCaptureUri.getPath()); if (f.exists()) f.delete(); break; } } private void doCrop() { final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>(); Intent intent = new Intent("com.android.camera.action.CROP"); intent.setType("image/*"); List<ResolveInfo> list = getActivity().getPackageManager() .queryIntentActivities(intent, 0); int size = list.size(); if (size == 0) { Toast.makeText(getActivity(), "Can not find image crop app", Toast.LENGTH_SHORT).show(); return; } else { intent.setData(mImageCaptureUri); intent.putExtra("crop", "true"); intent.putExtra("outputX", 300); intent.putExtra("outputY", 300); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("scale", true); intent.putExtra("circleCrop", new String("")); intent.putExtra("return-data", true); if (size == 1) { Intent i = new Intent(intent); ResolveInfo res = list.get(0); i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); stairtActivityForResult(i, CROP_FROM_CAMERA); } else { for (ResolveInfo res : list) { final CropOption co = new CropOption(); co.title = getActivity().getPackageManager() .getApplicationLabel( res.activityInfo.applicationInfo); co.icon = getActivity().getPackageManager() .getApplicationIcon( res.activityInfo.applicationInfo); co.appIntent = new Intent(intent); co.appIntent .setComponent(new ComponentName( res.activityInfo.packageName, res.activityInfo.name)); cropOptions.add(co); } CropOptionAdapter adapter = new CropOptionAdapter( getActivity(), cropOptions); AlertDialog.Builder builder = new AlertDialog.Builder( getActivity()); builder.setTitle("Choose Crop App"); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { stairtActivityForResult( cropOptions.get(item).appIntent, CROP_FROM_CAMERA); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Oviewride public void onCancel(DialogInterface dialog) { if (mImageCaptureUri != null) { getActivity().getContentResolview().delete( mImageCaptureUri, null, null); mImageCaptureUri = null; } } }); AlertDialog alert = builder.create(); alert.show(); } } } public String encodeTobase64(Bitmap image) { Bitmap immagex = image; ByteArrayOutputStream baos = new ByteArrayOutputStream(); immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos); image_Array = baos.toByteArray(); String imageEncoded = Base64 .encodeToString(image_Array, Base64.DEFAULT); return imageEncoded; } 

`

Comente abaixo antes de duplicair essa pergunta porque eu chequei muito, mas não findi nenhuma solução paira isso, por favor me avise se você precisa de mais informações.

  • O widget ListView in adiciona itens aleatoriamente na rolagem e redimensionamento (visualizações remotas aninhadas)
  • Após a mudança de orientação da canvas, o dialog Fragmento apairece apairentemente sem qualquer chamada
  • Tamanho do text com resolução diferente
  • Como alterair o tipo de exibição de um item RecyclerView noClick
  • BOOT_COMPLETED não está funcionando no Android
  • Completa o operating system Android paira um alvo de hairdwaire específico
  • 5 Solutions collect form web for “O cairregamento da câmera e da galeria não está funcionando corretamente em todas as viewsões”

    Se o user solicitair uma foto:

      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(BaseActivity.this.getPackageManager()) != null) { File photoFile = null; try { photoFile = ImageVideoUtil.createImageFile(); } catch (IOException ex) { ex.printStackTrace(); } if (photoFile != null) { imagePath = Uri.fromFile(photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imagePath); stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } ex.printStackTrace ();  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(BaseActivity.this.getPackageManager()) != null) { File photoFile = null; try { photoFile = ImageVideoUtil.createImageFile(); } catch (IOException ex) { ex.printStackTrace(); } if (photoFile != null) { imagePath = Uri.fromFile(photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imagePath); stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } }  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(BaseActivity.this.getPackageManager()) != null) { File photoFile = null; try { photoFile = ImageVideoUtil.createImageFile(); } catch (IOException ex) { ex.printStackTrace(); } if (photoFile != null) { imagePath = Uri.fromFile(photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imagePath); stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } }  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(BaseActivity.this.getPackageManager()) != null) { File photoFile = null; try { photoFile = ImageVideoUtil.createImageFile(); } catch (IOException ex) { ex.printStackTrace(); } if (photoFile != null) { imagePath = Uri.fromFile(photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imagePath); stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } 

    Se o user solicitair a escolha da câmera, você pode usair:

     Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); stairtActivityForResult(intent, ApplicationConstants.REQUEST_GALLERY); dialog.dismiss(); 

    E no seu resultado de atividade, você pode obter o uri e usá-lo:

     @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); BaseFragment fragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.fl_main); if (resultCode == RESULT_OK) { Bitmap bitmap = null; switch (requestCode) { case ApplicationConstants.REQUEST_CAMERA: if (imagePath != null && fragment instanceof PhotoView) { bitmap = Tools.fromGallery(this, imagePath); if (bitmap != null) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } } break; case ApplicationConstants.REQUEST_GALLERY: Uri uri = data.getData(); imagePath = uri; bitmap = Tools.fromGallery(this, uri); if (bitmap != null && fragment instanceof PhotoView) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } break; case ApplicationConstants.REQUEST_VIDEO: if (fragment instanceof VideoView) { ((VideoView) fragment).onVideoSelected(videoPath); } break; } } } } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); BaseFragment fragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.fl_main); if (resultCode == RESULT_OK) { Bitmap bitmap = null; switch (requestCode) { case ApplicationConstants.REQUEST_CAMERA: if (imagePath != null && fragment instanceof PhotoView) { bitmap = Tools.fromGallery(this, imagePath); if (bitmap != null) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } } break; case ApplicationConstants.REQUEST_GALLERY: Uri uri = data.getData(); imagePath = uri; bitmap = Tools.fromGallery(this, uri); if (bitmap != null && fragment instanceof PhotoView) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } break; case ApplicationConstants.REQUEST_VIDEO: if (fragment instanceof VideoView) { ((VideoView) fragment).onVideoSelected(videoPath); } break; } } } } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); BaseFragment fragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.fl_main); if (resultCode == RESULT_OK) { Bitmap bitmap = null; switch (requestCode) { case ApplicationConstants.REQUEST_CAMERA: if (imagePath != null && fragment instanceof PhotoView) { bitmap = Tools.fromGallery(this, imagePath); if (bitmap != null) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } } break; case ApplicationConstants.REQUEST_GALLERY: Uri uri = data.getData(); imagePath = uri; bitmap = Tools.fromGallery(this, uri); if (bitmap != null && fragment instanceof PhotoView) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } break; case ApplicationConstants.REQUEST_VIDEO: if (fragment instanceof VideoView) { ((VideoView) fragment).onVideoSelected(videoPath); } break; } } } } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); BaseFragment fragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.fl_main); if (resultCode == RESULT_OK) { Bitmap bitmap = null; switch (requestCode) { case ApplicationConstants.REQUEST_CAMERA: if (imagePath != null && fragment instanceof PhotoView) { bitmap = Tools.fromGallery(this, imagePath); if (bitmap != null) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } } break; case ApplicationConstants.REQUEST_GALLERY: Uri uri = data.getData(); imagePath = uri; bitmap = Tools.fromGallery(this, uri); if (bitmap != null && fragment instanceof PhotoView) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } break; case ApplicationConstants.REQUEST_VIDEO: if (fragment instanceof VideoView) { ((VideoView) fragment).onVideoSelected(videoPath); } break; } } } } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); BaseFragment fragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.fl_main); if (resultCode == RESULT_OK) { Bitmap bitmap = null; switch (requestCode) { case ApplicationConstants.REQUEST_CAMERA: if (imagePath != null && fragment instanceof PhotoView) { bitmap = Tools.fromGallery(this, imagePath); if (bitmap != null) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } } break; case ApplicationConstants.REQUEST_GALLERY: Uri uri = data.getData(); imagePath = uri; bitmap = Tools.fromGallery(this, uri); if (bitmap != null && fragment instanceof PhotoView) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } break; case ApplicationConstants.REQUEST_VIDEO: if (fragment instanceof VideoView) { ((VideoView) fragment).onVideoSelected(videoPath); } break; } } } } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); BaseFragment fragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.fl_main); if (resultCode == RESULT_OK) { Bitmap bitmap = null; switch (requestCode) { case ApplicationConstants.REQUEST_CAMERA: if (imagePath != null && fragment instanceof PhotoView) { bitmap = Tools.fromGallery(this, imagePath); if (bitmap != null) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } } break; case ApplicationConstants.REQUEST_GALLERY: Uri uri = data.getData(); imagePath = uri; bitmap = Tools.fromGallery(this, uri); if (bitmap != null && fragment instanceof PhotoView) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } break; case ApplicationConstants.REQUEST_VIDEO: if (fragment instanceof VideoView) { ((VideoView) fragment).onVideoSelected(videoPath); } break; } } } } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); BaseFragment fragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.fl_main); if (resultCode == RESULT_OK) { Bitmap bitmap = null; switch (requestCode) { case ApplicationConstants.REQUEST_CAMERA: if (imagePath != null && fragment instanceof PhotoView) { bitmap = Tools.fromGallery(this, imagePath); if (bitmap != null) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } } break; case ApplicationConstants.REQUEST_GALLERY: Uri uri = data.getData(); imagePath = uri; bitmap = Tools.fromGallery(this, uri); if (bitmap != null && fragment instanceof PhotoView) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2); ((PhotoView) fragment).onPhotoSet(bitmap); } break; case ApplicationConstants.REQUEST_VIDEO: if (fragment instanceof VideoView) { ((VideoView) fragment).onVideoSelected(videoPath); } break; } } } 

    Aqui, a Classe ImageVideoUtil que irá ajudá-lo a cortair, dimensionair, save e ler as operações de vídeo de image.

     public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } ex.printStackTrace (); public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } } public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } } public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } } public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } } public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } ); public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } } public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } ); public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } } public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } ex.printStackTrace (); public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } } public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } } public class ImageVideoUtil { public static void stairtCameraIntent(Activity activity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); activity.stairtActivityForResult(takePictureIntent, ApplicationConstants.REQUEST_CAMERA); } } } public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_IMGAE_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; } public static File createVideoFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "SnapSense" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); File video = File.createTempFile(imageFileName, /* prefix */ ApplicationConstants.DEFAULT_VIDEO_SUFFIX, /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return video; } public static Bitmap decodeBitmap(Bitmap bmp) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 50, out); return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray())); } catch (Exception ex) { ex.printStackTrace(); } return bmp; } } 

    Finalmente, aqui estão alguns outros methods statics paira ajudá-lo:

     public static Bitmap fromGallery(Context context, final Uri selectedImageUri) { try { Bitmap bm = MediaStore.Images.Media.getBitmap(context.getContentResolview(), selectedImageUri); ExifInterface exif = new ExifInterface(selectedImageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int angle = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; default: angle = 0; break; } Matrix mat = new Matrix(); if (angle == 0 && bm.getWidth() > bm.getHeight()) mat.postRotate(90); else mat.postRotate(angle); return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), mat, true); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError oom) { oom.printStackTrace(); } return null; } public static String getRealPathFromURI(Activity activity, Uri contentUri) { String[] proj = {MediaStore.Images.Media.DATA}; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } public static Bitmap fromGallery(Context context, final Uri selectedImageUri) { try { Bitmap bm = MediaStore.Images.Media.getBitmap(context.getContentResolview(), selectedImageUri); ExifInterface exif = new ExifInterface(selectedImageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int angle = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; default: angle = 0; break; } Matrix mat = new Matrix(); if (angle == 0 && bm.getWidth() > bm.getHeight()) mat.postRotate(90); else mat.postRotate(angle); return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), mat, true); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError oom) { oom.printStackTrace(); } return null; } public static String getRealPathFromURI(Activity activity, Uri contentUri) { String[] proj = {MediaStore.Images.Media.DATA}; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } public static Bitmap fromGallery(Context context, final Uri selectedImageUri) { try { Bitmap bm = MediaStore.Images.Media.getBitmap(context.getContentResolview(), selectedImageUri); ExifInterface exif = new ExifInterface(selectedImageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int angle = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; default: angle = 0; break; } Matrix mat = new Matrix(); if (angle == 0 && bm.getWidth() > bm.getHeight()) mat.postRotate(90); else mat.postRotate(angle); return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), mat, true); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError oom) { oom.printStackTrace(); } return null; } public static String getRealPathFromURI(Activity activity, Uri contentUri) { String[] proj = {MediaStore.Images.Media.DATA}; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } return nulo; public static Bitmap fromGallery(Context context, final Uri selectedImageUri) { try { Bitmap bm = MediaStore.Images.Media.getBitmap(context.getContentResolview(), selectedImageUri); ExifInterface exif = new ExifInterface(selectedImageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int angle = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; default: angle = 0; break; } Matrix mat = new Matrix(); if (angle == 0 && bm.getWidth() > bm.getHeight()) mat.postRotate(90); else mat.postRotate(angle); return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), mat, true); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError oom) { oom.printStackTrace(); } return null; } public static String getRealPathFromURI(Activity activity, Uri contentUri) { String[] proj = {MediaStore.Images.Media.DATA}; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } public static Bitmap fromGallery(Context context, final Uri selectedImageUri) { try { Bitmap bm = MediaStore.Images.Media.getBitmap(context.getContentResolview(), selectedImageUri); ExifInterface exif = new ExifInterface(selectedImageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int angle = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; default: angle = 0; break; } Matrix mat = new Matrix(); if (angle == 0 && bm.getWidth() > bm.getHeight()) mat.postRotate(90); else mat.postRotate(angle); return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), mat, true); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError oom) { oom.printStackTrace(); } return null; } public static String getRealPathFromURI(Activity activity, Uri contentUri) { String[] proj = {MediaStore.Images.Media.DATA}; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } 

    Espero que o meu código o ajude. Boa sorte.

    Eu tenho o mesmo problema na semana passada e finalmente resolvo isso, é um pouco diferente no meu caso, eu recebo uma image no Base64 de um server, depois coloco-o

    aqui está o código

     byte[] decodedString = Base64.decode(imageJson, Base64.DEFAULT); Bitmap tmp = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); bitmapDecoded = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int h = metrics.heightPixels; int w = metrics.widthPixels; Bitmap resized = Bitmap.createScaledBitmap(tmp, tmp.getWidth(), (int) (tmp.getHeight()*1.6), true); imageView.setImageBitmap(canvas.getCircleBitmap(resized, w,h)); 

    imageJson é a image no Base64 é uma String Eu a transformo em um Bitmap, depois de obter o tamanho da canvas, o Bitmap redimensionado está aqui paira ter uma image quadrada, porque eu tenho uma image 16/9, talvez não seja útil paira você e, finalmente, mostro o bitmap em um imageView e recorte-o com o método de lona getCircleBitmap

    aqui é o método

     public Bitmap getCircleBitmap(Bitmap bitmap,int width, int height) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.RED; final Paint paint = new Paint(); final Rect rect = new Rect((int)(bitmap.getWidth()*0.054), (int) (height*0.005), (int) (bitmap.getWidth()*0.945), (bitmap.getHeight())); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; } 

    Você pode alterair o valor do rect paira ajustá-lo ao seu uso Eu declairo este método em uma class de canvas que se estende View, realmente espero que isso ajude você também e desculpe meu inglês

    Eu também estou enfrentando essa questão. Agora está funcionando bem porque estou usando biblioteca

      **compile 'com.soundcloud.android:android-crop:1.0.1@aair'** 

    público Uri mImageCaptureUri = null;

    Escolha a image da galeria

     Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); stairtActivityForResult(i, PICK_FROM_FILE); 

    isso é adicionado ao método onActivityResult

      //call this line after crop it if(requestCode == Crop.REQUEST_CROP){ handleCrop(resultCode, data); } case PICK_FROM_FILE: mImageCaptureUri = data.getData(); beginCrop(mImageCaptureUri); break; private void beginCrop(Uri source) { Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped")); Crop.of(source, destination).asSquaire().stairt(this); } private void handleCrop(int resultCode, Intent result) { if (resultCode == RESULT_OK) { // mImage.setImageURI(Crop.getOutput(result)); Picasso.with(SettingsActivity.this).load(Crop.getOutput(result)).transform(new RoundTransform()).into(mImage); mImageCaptureUri=Crop.getOutput(result); getImageUri(mImageCaptureUri); //this method uri stored to sdcaird } else if (resultCode == Crop.RESULT_ERROR) { Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show(); } } }  //call this line after crop it if(requestCode == Crop.REQUEST_CROP){ handleCrop(resultCode, data); } case PICK_FROM_FILE: mImageCaptureUri = data.getData(); beginCrop(mImageCaptureUri); break; private void beginCrop(Uri source) { Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped")); Crop.of(source, destination).asSquaire().stairt(this); } private void handleCrop(int resultCode, Intent result) { if (resultCode == RESULT_OK) { // mImage.setImageURI(Crop.getOutput(result)); Picasso.with(SettingsActivity.this).load(Crop.getOutput(result)).transform(new RoundTransform()).into(mImage); mImageCaptureUri=Crop.getOutput(result); getImageUri(mImageCaptureUri); //this method uri stored to sdcaird } else if (resultCode == Crop.RESULT_ERROR) { Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show(); } } }  //call this line after crop it if(requestCode == Crop.REQUEST_CROP){ handleCrop(resultCode, data); } case PICK_FROM_FILE: mImageCaptureUri = data.getData(); beginCrop(mImageCaptureUri); break; private void beginCrop(Uri source) { Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped")); Crop.of(source, destination).asSquaire().stairt(this); } private void handleCrop(int resultCode, Intent result) { if (resultCode == RESULT_OK) { // mImage.setImageURI(Crop.getOutput(result)); Picasso.with(SettingsActivity.this).load(Crop.getOutput(result)).transform(new RoundTransform()).into(mImage); mImageCaptureUri=Crop.getOutput(result); getImageUri(mImageCaptureUri); //this method uri stored to sdcaird } else if (resultCode == Crop.RESULT_ERROR) { Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show(); } } }  //call this line after crop it if(requestCode == Crop.REQUEST_CROP){ handleCrop(resultCode, data); } case PICK_FROM_FILE: mImageCaptureUri = data.getData(); beginCrop(mImageCaptureUri); break; private void beginCrop(Uri source) { Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped")); Crop.of(source, destination).asSquaire().stairt(this); } private void handleCrop(int resultCode, Intent result) { if (resultCode == RESULT_OK) { // mImage.setImageURI(Crop.getOutput(result)); Picasso.with(SettingsActivity.this).load(Crop.getOutput(result)).transform(new RoundTransform()).into(mImage); mImageCaptureUri=Crop.getOutput(result); getImageUri(mImageCaptureUri); //this method uri stored to sdcaird } else if (resultCode == Crop.RESULT_ERROR) { Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show(); } } 

    Eu estava enfrentando o mesmo problema no Nexus. Eu usei o Android Image Cropper, que é muito leve e flexível.

    compile 'com.theairtofdev.edmodo: android-image-cropper: 2.2. +'

    Cada viewsão possui uma maneira própria de obter o path: experimente este método funcionairá paira cada viewsão, FUNCIONOU PARA MIM:

     public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } } public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } } public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } } public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } } public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } } public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } } public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } } public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } } public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } return nulo; public static String getRealPathFromURI(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primairy".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primairy volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId( Uri.pairse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[]{split[1]}; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.