ImageView.setImageURI does NOT work when trying to assign a R.drawable.X Uri

Viewed 94764

is related to:

Need suggestion about a mixed "Uri / int id" images ambient

now my problem is that:

ImageView imgView=(ImageView)findViewById(R.id.imgView);
Uri imgUri=Uri.parse("android.resource://my.package.name/"+R.drawable.image);
imageView.setImageURI(imgUri);

does NOT work . why?

i know that

imgView.setImageDrawable(Drawable.createFromStream(
                    getContentResolver().openInputStream(imgUri),
                    null));

work.

but that does NOT solve my problem. because I want to set the image with an uri independenty if this come from a resource or come from the camera ACTION_PICK intent...

any suggestions are welcome. Thank you. Regards

4 Answers

your should do something like this

Uri imgUri = Uri.parse("android.resource://my.package.name/drawable/image_sky");

or if you want like this

Uri imgUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "image_sky");

First of all see, whether you are not override onRestart method and refreshing it.

If you will refresh the activity the image will not set.

Related