1

am sending an image with help of intent as follow

Uri profileImage = Uri.parse("android.resource://Tset/res/drawable-hdpi/arr.jpeg");
            details.setType("image/png");
            details.putExtra(Intent.EXTRA_STREAM, profileImage);
            startActivity(details);

how do i can get the image path in my receiving end activity ?

Mohan Raj
  • 590
  • 3
  • 8
  • 22

3 Answers3

3

Try This Pass image url from current activity using intent

Intent myIntent = new Intent(this, MyImageViewActivity.class);
Bundle bundle = new Bundle();
bundle.putString("image", path);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);

Here path is

String path="android.resource://Tset/res/drawable-hdpi/arr.jpeg"

in your receiving activity

Bundle bundle = this.getIntent().getExtras();
String path = bundle.getString("image");
  • bundle.putString("image", path); here how to pass the value for "path"? – Mohan Raj Jun 15 '13 at 10:29
  • @LiveITup can you explain what this is **android.resource://Tset/res/drawable-hdpi/arr.jpeg**. you can acess drawable in the other activity also. so if you explain will help us give better answer – Raghunandan Jun 15 '13 at 10:35
  • this is the path of my image in drawable folder ! – Mohan Raj Jun 15 '13 at 10:55
  • are the activities in the same package?? if so you can refer to the drawable in the next activity as R.drawable.imagename – Raghunandan Jun 15 '13 at 10:57
  • @LiveITup like ImageView iv = (ImageView) findViewById(R.id.imageView1); iv.setBackgroundResource(R.drawable.ic_launcher); ic_launcher as the iamge name – Raghunandan Jun 15 '13 at 11:00
  • thanks for ur relaying helps ! ! i done it and post it as answer ! – Mohan Raj Jun 15 '13 at 12:38
2

Finally i done it with help of id of the image as follow ! ! thanks for all of ur reply ! !

  profilePictureID=R.drawable.image name;//name of image in drawable folder dont use extensions like.jpg and all  
  IntentObject.putExtra("ImageID",profilePictureID);
  startActivity(IntenetObject);

In receiving activity

 int pictureId=getIntent().getIntExtra("ImageID",0);
 profilePicture.setImageResource(pictureId);
Mohan Raj
  • 590
  • 3
  • 8
  • 22
  • also this does not make sense since you can access the drawable image just be referring as R.drawable.imagename. and why did you unaccept my answer? for all my effort not even a upvote. very frustrating – Raghunandan Jun 15 '13 at 13:27
  • 1
    @Raghunandan am not doing it for an image it's a part of my list view ! am having loads of image and based on the image gets clicks i need to send the Id of the image to next activity ! ! For a single image navigation i could directly refer it from my next activity with out intent message exchange of intent ! – Mohan Raj Jun 16 '13 at 06:51
  • even then the edit part of my solution works you are passing an int id and not the uri. – Raghunandan Jun 16 '13 at 06:54
  • also how can you know the name of the image on list item click. it should work dynamically in that case and you should include more info in your question. i don't think its a good approach – Raghunandan Jun 16 '13 at 07:00
  • 1
    i 've defined a custom adapter that stores all the data belongs to list view i just instantiate the adapter in onCreate() so that i can access all the data in list ! ! – Mohan Raj Jun 16 '13 at 07:08
  • that has nothing to with passing the drawable id. in any case post your code. you have to include more info. you have not provided anything. din't mention about listview or custom adapter – Raghunandan Jun 16 '13 at 07:10
  • i wrapped those things that's why id didn't mention! my concern was just passing an intent to next activity with an image ! – Mohan Raj Jun 16 '13 at 11:01
  • that's exactly what was answered in the answer posted – Raghunandan Jun 16 '13 at 11:01
1

Try this..

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
startActivity(intent);
selva_pollachi
  • 4,147
  • 4
  • 29
  • 42