Java和Android的:如何打开多个文件的意图是什么? [英] Java and Android: How to open several files with an Intent?

查看:111
本文介绍了Java和Android的:如何打开多个文件的意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,这是一个简单的问题,但我没能找到答案。

I'm sure this is a trivial question, but I failed to find an answer.

我在做一个Android应用程序从我想要打开的图像浏览器 示出多个图像。我知道如何只用一个形象做到这一点:

I'm making an Android app from which I want to open the image viewer showing several images. I know how to do this with only one image:

    Intent intent = new Intent();  
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file1 = new File("/mnt/sdcard/photos/20397a.jpg");
    intent.setDataAndType(Uri.fromFile(file1), "image/jpg");
    startActivity(intent);

这完美的作品。但我怎么通过一些图片给观众?

This works perfectly. But how do I pass several images to the viewer?

谢谢! L;

推荐答案

您需要列出您希望查看在阵列中的所有文件。然后你显示阵列中的一个,当你拖动,就显示下一个图像。

You need to list all files you want to view in a array. Then you display one of the array and when you drag, you show the next image.

ArrayList list;

private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // Ansi date format

list = new ArrayList();  
  String path = "c:/temp/";  
  File dir = new File(path);   
  for (String dirListing : dir.list()) {
    if ((dirListing.endsWith(".jpg")) ||
      (dirListing.endsWith(".png")) || 
      (dirListing.endsWith(".gif"))) {
      try { // write all file-info to a arraylist
        File f = new File(path+dirListing);      
        list.add(f.getCanonicalPath()); 
        list.add(f.getName());
        list.add(String.valueOf(f.length()));
        String lastModified = dateFormat.format(new Date(f.lastModified()));
        list.add(lastModified);
      }
      catch (IOException e) {
        e.printStackTrace();
      }
      catch (IndexOutOfBoundsException e) {
        e.printStackTrace();
      }
    }
  }

现在,你可以阅读阵列和一个然后显示一个。

Now you can read the array and display then one by one.

这篇关于Java和Android的:如何打开多个文件的意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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