views:

40

answers:

2

I have 2 apps running, and I need to pass an image resource from the first app to the second.

The ImageView have a setImageURI(Uri) method, that I could use in the second app, but does not have a getUri() for me to use in the first.

Any idea how to do this?

-- update

looks like Content Providers can solve the problem. (studying)

A: 

The only way is to pass the data to the second Activity when you start it. If you check out the Intent API you can pass the Uri using one of the putExtra() methods, and in the onCreate for the new Activity you can retrieve the Uri using getStringExtra().

BrennaSoft
Thanks for share your thoughts. Unfortunately, I can't pass the Uri because I don't know how to get it.. The ImageView has no getUri method.
Tom Brito
:o Tom, where are you supossing to take the Uri for the first time??
Jorgesys
@Tom Brito, well you have the URI because you are loading the ImageView.
BrennaSoft
I'm loading the ImageView using R.drawable.myimage. There is no Uri constructor for this... There is a UriMatcher , but it is not the solution either..
Tom Brito
@Tom Brito Then in the other activity load the Image view the same way.imageView.setImageResource(R.drawable.myimage);
BrennaSoft
The other app don't have this resource.. ;)
Tom Brito
For this time, the resource could be on the device, outside both apps, and I just pass the Uri using the Intent. It worked well for this specific problem. In others maybe the Content Providers solve best..
Tom Brito
A: 

You can pass a (Bitmap)Drawable this way:

// sending side
BitmapDrawable bd = (BitmapDrawable)imageView.getDrawable();
intent.putExtra("img", bd);

// receiving side
Bitmap b = (Bitmap) intent.getParcelable("img");
imageView.setImageBitmap(b);
alex