-1

//here is my gallery intent

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    startActivityForResult(photoPickerIntent,2);



protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
           if (requestCode == 2) {
                Bitmap bm=null;
                if (data != null) {
                    try {
                        bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
                        imageView.setImageBitmap(bm);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                Uri tempUri = getImageUri(getApplicationContext(), bm);
                File finalFile = new File(getRealPathFromURI(tempUri));
            } }

I am implementing camera and gallery intent in my android app.when i capture the through camera the image is displayed in imageview but if i try to display the same camera image through gallery intent the image is not displaying.

Note:captured image is not displaying through gallery intent but other folder images are displaying in imageview

Vishali
  • 1,307
  • 4
  • 23
  • 41

2 Answers2

2

Bug #1: ACTION_PICK does not use a MIME type. Either use ACTION_GET_CONTENT with a MIME type, or use ACTION_PICK with a collection Uri (e.g., MediaStore.Images.Media.EXTERNAL_CONTENT_URI).

Bug #2: You are assuming that MediaStore knows how to get an image from that Uri. Since the Uri may not have come from the MediaStore, that is an incorrect assumption. Use Glide or Picasso to load the image into your ImageView.

Bug #3: You are loading the image on the main application thread. This will freeze your UI while the image is being loaded. Use Glide or Picasso to load the image into your ImageView, as they know how to do that work on a background thread.

Bug #4: You appear to have copied some code that "gets a Uri for a bitmap". You do not need to do that. You already have a Uri for the image. It is data.getData(), and you used it to try to load the image in the first place.

Bug #5: You appear to have copied some code that purports to get "a real path for a Uri". There is no reliable way of doing that. If you want a File that contains the data from the image, use ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri, then use that InputStream to copy the bytes to a FileOutputStream for some file that you control.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Try to use the below code, Hope it will help you.

Uri selectedImage = data.getData();
Bitmap bitmap = null;
try {
   bitmap = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(selectedImage));
    } catch (FileNotFoundException e) {
         e.printStackTrace();
   }

 imageView.setImageBitmap(bitmap);
Sanjay Bhalani
  • 2,424
  • 18
  • 44