简体   繁体   中英

Open remote image in gallery

I have an app with thumbnails and when the user touch a thumb, I would like to open the full image in fullscreen. I try opening the image in the default Gallery app, but it doesn't work on all devices.

Here's the snippet :

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url_of_the_remote_image_here));
intent.setType("image/jpg");
startActivity(intent);

On Nexus S running 4.1, I get :

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=image/jpg }

I try several snippets of code and many were opening the image in the browser. Because all Android devices have default gallery, shouldn't it be possible to open the remote image using it?

You should never assume there's activty to handle your intenet, so always wrap startActivity() in try/catch . I'd use correct mime type image/jpeg , but in fact I'd replace it with just more generic image/* .

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url_of_the_remote_image_here));
intent.setType("image/*");
try {
   startActivity(intent);
} catch( Exception e ) {
   e.printStatckTrace();
}

This might have your answer. The person asking the question was able to display it in a browser. Then there is a link to the solution using the Intent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM