views:

50

answers:

2

We can view an image with code:

Intent intent = new Intent();  

intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("/sdcard/test.jpg");
intent.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(intent);

What if we have some images? How can we put the extras to let the viewer know we have

/sdcard/a.jpg, /sdcard/b.jpg, /sdcard/c.jpg ?

I hope to do this in a time because starting an activity is very expensive.

can any one help me? Thanks!

A: 

http://developer.android.com/reference/java/io/File.html#exists%28%29

Voulnet
Maybe I didn't make my questions clear enough. I mean what if we have some, not one, images? At present, I know how to view one image, but how to view multiple images at a time?
Henry Sou
Well, I went through a similar problem, so I used a WebView, and I fed it an HTML code with <img> tags that have src attributes with values of the images path. To test, create a WebView and feed it an HTML code (in a String) with some random online image URL as the src attribute of some img tag in your HTML code that's being fed to the WebView. If it works (and it will) try feeding it a filepath instead, this way you can construct your HTML code dynamically (looping over the number of images and adding a corresponding <img> tag for each one with its filepath as src). see WebView's loadData
Voulnet
A: 

You can't.

The whole system of intents and uris is to either do an action on one item, or do an action on all items. See http://developer.android.com/reference/android/content/Intent.html and search for "content://contacts/people/1" and "content://contacts/people/" Have you tried looking for the intent that would let the viewer show all images in "/sdcard/". Even better is to plug into the content provider of that native viewer.

pjv