0

I am using the ImageView to display a image with a image stored in SD card. Like this-

    ImageView grp_icon=(ImageView)gridView.findViewById(R.id.grid_item_image);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            String path="/sdcard/Letsmeet/letsmeet_media/group_images/"+gridImage[position];
            Bitmap bitmap = BitmapFactory.decodeFile(path, options);
            grp_icon.setImageBitmap(bitmap);

And I am trying to get the image location to display the same image in another activity by sending the location in Intent. But it gives a different location Why?

The code where I get the ImageView image location is

String groupName=((TextView) v.findViewById(R.id.grid_item_label)).getText().toString();
                ImageView grp_image=(ImageView)v.findViewById(R.id.grid_item_image);
                Bitmap b=((BitmapDrawable)grp_image.getDrawable()).getBitmap();
                Uri image=getImageUri(getActivity().getApplicationContext(), b);
                String path=image.toString();
                Intent toMangeGroup=new Intent(getActivity(),ManageGroup.class);
                Bundle bundle=new Bundle();
                bundle.putString("grp_name", groupName);
                bundle.putString("grp_image", path);
                toMangeGroup.putExtras(bundle);
                startActivity(toMangeGroup);

Here I am getting the path as "content://media/external/images/media/42424" but the actual path of the image is "/sdcard/Letsmeet/letsmeet_media/group_images/1395247992445"

John R
  • 2,078
  • 8
  • 35
  • 58
dharanbro
  • 1,327
  • 4
  • 17
  • 40
  • i am not sure about this but then it could be that since you are getting the drawable from the image that is why it is not returning the sdcard image path, since the sdcard image path gets converted into the bitmap that you are setting – Rat-a-tat-a-tat Ratatouille Mar 25 '14 at 04:34
  • 1
    Have a look at this Nikolay Nikiforchuk answer http://stackoverflow.com/questions/3401579/get-filename-and-path-from-uri-from-mediastore . It tells how you can convert to your full path. –  Mar 25 '14 at 04:38
  • A little modification would be needed. :-) –  Mar 25 '14 at 04:39
  • @DharanBro i have posted that in the answer. you can accept if you feel that helped thanks. :-) –  Mar 25 '14 at 09:51

4 Answers4

0
System.out.println("this is path where stored.."
                + Environment.getExternalStorageDirectory()
                        .getAbsolutePath());
Android
  • 8,995
  • 9
  • 67
  • 108
0

Try this for getting file path on sdcard:

String filePath = Environment.getExternalStorageDirectory().toString() + File.separator + "Letsmeet/letsmeet_media/group_images/" + gridImage[position];

Sujith Thankachan
  • 3,508
  • 2
  • 20
  • 25
0

use this code:may help you..

Bitmap mybit=BitmapFactory.decodeFile(file1.getAbsolutePath());
image.setImageBitmap(mybit);

used to store your image in file format and get the image from that path.

prakash
  • 1,413
  • 1
  • 21
  • 33
0

Look at this Get filename and path from uri from mediastore. The answer provided by Nikolay Nikiforchuk is the way to go. And that does not only work with the mediafile but will also work good with all the files stored on SDCard

just replace this line

int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

with this one

int column_index = cursor.getColumnIndexOrThrow("_data");

That would work fine.

Community
  • 1
  • 1