启动意图查看器中显示的URL图像 [英] Launch intent viewer to display image from url

查看:112
本文介绍了启动意图查看器中显示的URL图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形象的网址。我需要做的就是启动默认的图像浏览器使用意图的图像。

I have the url of an image. What i need to do is launch the default image viewer for images using an intent.

我试着通过启动它:

Uri uri = Uri.parse("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png");  
Intent it = new Intent(Intent.ACTION_VIEW);
it.setDataAndType(uri, "image/*")
startActivity(it);

不过,这是行不通的。如果我不指定数据的类型,目的启动浏览器,因为数据是一个网址。它的工作原理基本上是(因为你可以看到在浏览器中的图像),但我想是有画廊显示图像的我。

But it doesn't work. If I do not specify the type of data, the intent launches the browser since the data is a url. It works basically (since you can see the image on the browser) but what I would like is to have the gallery display the image for me.

我还可以下载图片到一个位图,但我仍然不知道如何使用画廊(如果这甚至有可能)来显示位图。任何想法?

I can also download the image into a Bitmap but I would still not know how to display the Bitmap using the gallery (if that's even possible). Any ideas?

编辑:我试图保存位图缓存,然后启动浏览器上的文件,但它不工作。你能找出我的code任何错误? (该实用工具类是一类我写的。该方法简单地创建位图,它的工作原理,这不是问题)

I tried saving the bitmap to the cache and then launch the viewer on that file but it doesn't work. Can you spot any mistakes on my code? (The Utilities class is a class i wrote. The method simply creates the Bitmap. It works, that's not the problem)

File temp = File.createTempFile("tempImage", ".jpg", getContext().getCacheDir());
Bitmap bmp = Utilities.loadBitmap(largeUrl.toString());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(temp));
bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.close();
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(temp), "image/jpg");
((Activity) getContext()).startActivity(intent);

编辑2 :我决定,我可能需要下载的图像毕竟,所以我决定先救他们在SD卡上。创建其他问题。我问了一个<一个href="http://stackoverflow.com/questions/2954594/launching-intent-action-view-intent-not-working-on-saved-image-file">new问题为,因为它是一个不同的问题。

EDIT 2: I decided that i may need the downloaded images after all so i decided to first save them on the sd card. That created other problems. I asked a new question for that since it is a different problem.

推荐答案

这是在分拆问题,我贴回答

这篇关于启动意图查看器中显示的URL图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆