Android的ACTION_VIEW多张图片 [英] Android ACTION_VIEW Multiple Images

查看:230
本文介绍了Android的ACTION_VIEW多张图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一至三张照片,我想我的应用程序来显示。我不知道,直到运行时的很多照片是究竟是如何从网上下载的。

I have between one and three photos I'd like my app to display. I won't know until runtime exactly how many photos are downloaded from the Internet.

我无法弄清楚如何创建一个Intent来显示照片。现在我创造我做的东西像一个文件夹下缓存他们在SD卡(没有错误检查):

I can't figure out how to create an Intent to display the photos. Right now I'm caching them on the sdcard under a folder I create by doing something like (sans error checking):

final File externalDirectory = Environment.getExternalStorageDirectory();
final String folder = externalDirectory.getAbsolutePath() + "/Android/data/" + packageName + "/files/";

这是在 Android开发者参考解释

我可以得到一张照片,显示通过执行以下操作:

I can get one photo to display by doing the following:

final Uri uri = Uri.fromFile(file);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
Util.startActivity(this, intent);

其中,文件是一个保存的照片文件。

Where file is the file of a saved photo.

如果有帮助,我可以在图像保存到提供给我的应用程序的任何位置,但是我会preFER不使照片显示了与用户的其他个人照片列为可能令人反感。

If it helps, I could save the images to any location available to my app, however I would prefer to not have the photos show up listed with the user's other personal photos as that may be annoying.

图片浏览器有一个菜单选项幻灯片,所以它必须了解多张照片。

The Image Viewer has a menu option "Slideshow", so it must know about multiple photos.

我可以创建自己的图像浏览器,但是,似乎是额外的工作,并超过了我,我会合理地预期。即使我这样做,我想用户可以安装一个第三方的图像浏览器,并得到与平移,缩放,分享更好的体验,...

I could create my own Image Viewer, but that seems like extra work and beyond what I would I reasonably expect. Even if I did this, I would like the user to be able to install a 3rd party Image Viewer and get a better experience with pan, zoom, share, ...

我尝试使用的缓存照片文件创建开放的目录,但图像查看器显示一个黑色的页面。如果我通过在文件中,它显示只是一个文件,并没有其他人。

I tried using the directory of the cached photo files to create the Uri, but the Image Viewer shows a black page. If I pass in the file, it shows just that one file and no others.

我知道这一定是可能的,因为我可以看到使用库的应用程序,并显示照片,如果我手动选择的文件夹。每次我研究这个问题,评论说,这是不可能的,以显示多个图像。

I know this must be possible because I can see use the Gallery app and show the photos if I manually select the folder. Everytime I research this issue, the comments say it's not possible to show multiple images.

我怀疑有一些魔法咒语,但什么?

I suspect there's some magic incantation, but what?

推荐答案

我觉得你的目标是在你的控制。如果查看器应用程序被设计为处理多发的图像或目录,你可能会问它来显示你所想要的,但你被定义为观看者的模式。

I think your goal is out of your control. If the viewer app is designed to handle mutiple images or a directory, you may ask it to show as you want, but you are defined to the viewer's pattern.

我已经安装了第三方的图像浏览器名为<一个href="https://market.android.com/details?id=com.alensw.PicFolder#?t=W251bGwsMSwxLDUwMSwiY29tLmFsZW5zdy5QaWNGb2xkZXIiXQ.."相对=nofollow>下载快。我只是测试你的code段,系统弹出一个选择对话框,让我选择的应用程序,以显示该文件夹中的图像。如果我选择本土画廊,我看到的只是一个空文件夹,而下载快的工作,因为我想要的。

I have installed a third-party image viewer called QuickPic. I just tested your code snippet and the system popped up a chooser dialog to let me select the app to show the images in the folder. If I select native gallery, what I see is just an empty folder, while the Quickpic works as I want.

PS:我告诉我的应用程序的文件夹的URI是这样的:

PS: I tell my app the Uri of the folder this way:

                intent.setDataAndType(Uri.fromFile(new File("//mnt/sdcard/test/")), MimeTypeMap.getSingleton().getMimeTypeFromExtension("png"));

这篇关于Android的ACTION_VIEW多张图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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