机器人编程:从哪里开始创建一个简单的文件浏览器? [英] Android Programming: Where To Start For Creating A Simple File Browser?

查看:147
本文介绍了机器人编程:从哪里开始创建一个简单的文件浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想作一个文件浏览器,会做两件事情: 1)允许用户浏览和选择一个目录 2)允许用户浏览他们的SD卡中的所有文件

I would like to make a file browser that will do two things: 1) Allow the user to browse and select a directory 2) Allow the user to browse all files on their sdcard

我看的教程,但似乎无法找到任何? 是否有人可以帮助我,无论怎么解释我是什么code需要做才能有一个简单的文件浏览器或我提供一个链接到一个教程/源$ C ​​$ C?

I've looked for tutorials but can't seem to find any? Can someone please help me by either explaining how what my code would need to do in order to have a simple file browser or providing me with a link to a tutorial/source code?

请和谢谢!

推荐答案

如果你其实更感兴趣的是学习写你自己的,我建议你服用了良好的通过的File 类文档。这就是你要去的地方在做的大部分工作。

If you're actually more interested in learning to write your own, I'd suggest taking a good long read through the File class documentation. That's where you're going to be doing most of the work.

在SD卡/其他外部存储为Android的情况下,你会想先检查,以确保外部存储设备安装,并提供试图读取它之前,使用的Environment 类:

In the case of SD cards/other external storage for Android, you'll want to first check to ensure that the external storage is mounted and available before trying to read it, using the Environment class:

String extState = Environment.getExternalStorageState();
//you may also want to add (...|| Environment.MEDIA_MOUNTED_READ_ONLY)
//if you are only interested in reading the filesystem
if(!extState.equals(Environment.MEDIA_MOUNTED)) {
    //handle error here
}
else {
    //do your file work here
}

一旦你已经确定了外部存储的正常状态,一个简单的方式开始是使用文件的listFiles()方法,像这样:

Once you've determined the proper state of the external storage, a simple way to start is to use File's listFiles() method, like so:

//there is also getRootDirectory(), getDataDirectory(), etc. in the docs
File sd = Environment.getExternalStorageDirectory();
//This will return an array with all the Files (directories and files)
//in the external storage folder
File[] sdDirList = sd.listFiles();

然后就可以开始使用FileFilters来缩小搜索结果:

You can then start using FileFilters to narrow down your results:

FileFilter filterDirectoriesOnly = new FileFilter() {
    public boolean accept(File file) {
        return file.isDirectory();
    }
};
File[] sdDirectories = sd.listFiles(filterDirectoriesOnly);

从那里,只是通读文档,找到你想用它做的事情的类型,然后你可以绑到这些名单适配器等工作。

From there on, just read through the docs to find the type of thing you're looking to do with it, and then you can work on tying these into list adapters, etc.

希望这有助于!

这篇关于机器人编程:从哪里开始创建一个简单的文件浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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