user3739970
user3739970

Reputation: 591

Set uri.parse resource as ImageView

i am trying to set ImageView as resource of uri.pare.

to perform this task i tried this but it's not working: failed to load image

method 1:

Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
                intent.addCategory(Intent.CATEGORY_DEFAULT);
                intent.setDataAndType(Uri.parse("R.id.imageView1"),"image/*");
                intent.putExtra("mimeType", "image/*");
                startActivity(Intent.createChooser(intent, "Set as:"));

method 2:

Intent intent = new Intent();
                 intent.setAction(Intent.ACTION_VIEW);
                 intent.setDataAndType(Uri.parse("R.id.imageView1"),"image/*");
                 startActivity(intent);

i am not able to set ImageView as resource of uri.parse, so please help me how do i set ImageView as resource of uri.parse

i found a code but i am not understanding how to adjust this code with my code:

this is i found:

ImageView imgView = (ImageView) findViewById(R.id.image3);

    imgView.setImageURI(Uri.parse("file://mnt/sdcard/d2.jpg"));

how do i adjust it with my code:

intent.setDataAndType(Uri.parse("R.id.imageView1"),"image/*");

Upvotes: 2

Views: 1223

Answers (2)

user3739970
user3739970

Reputation: 591

"Setting uri.parse resource as ImageView" is not works and i failed to found such a way to "Set uri.parse resource as ImageView" the simple and working way is to save image to sd card then use code like this:

intent.setDataAndType(Uri.parse("file://mnt/sdcard/temp_image0.png"),"image/*");

see this post to find out saving image to sd card: how to save ViewPager Current image to sd card on button click

Upvotes: 0

Jim
Jim

Reputation: 10288

ImageView.setImageURI only takes Android content URI as stated here:

https://groups.google.com/forum/?fromgroups=#!topic/android-developers/jupslaeAEuo

In other words, it takes things like "file://" or "content://" URI's, not resource ID's like what you are trying to do.

If you want to do that, the only way that I know how, and what I did, was to write the resource to a file and then pass the file path to the ImageView URI. There are many examples of how to write files to the system (including thinking about using the SDCARD, etc.)

I'm pretty sure you could write a ContentProvider that will resolve the "content://" or "file://" schemes using the ContentProvider openFile / openInputStream methods, but I abandoned that before I needed it. I might finish it - if anyone is curious how it works...

Upvotes: 1

Related Questions