package com.test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
public class Main extends ListActivity {
/* 变量声明
items:存放显示的名称
paths:存放文件路径
rootPath:起始目录 */
private List<String> items=null;
private List<String> paths=null;
private String rootPath="/";
private TextView mPath;
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mPath=(TextView)findViewById(R.id.mPath);
getFileDir(rootPath);
}
/* 取得文件架构的方法 */
private void getFileDir(String filePath)
{
/* 设置目前所在路径 */
mPath.setText(filePath);
items=new ArrayList<String>();
paths=new ArrayList<String>();
File f=new File(filePath);
File[] files=f.listFiles();
if(!filePath.equals(rootPath))
{
/* 第一笔设置为[回到根目录] */
items.add("b1");
paths.add(rootPath);
/* 第二笔设置为[回到上一层] */
items.add("b2");
paths.add(f.getParent());
}
/* 将所有文件添加ArrayList中 */
for(int i=0;i<files.length;i++)
{
File file=files[i];
items.add(file.getName());
paths.add(file.getPath());
}
/* 使用自定义的MyAdapter来将数据传入ListActivity */
setListAdapter(new MyAdapter(this,items,paths));
}
/* 设置ListItem被点击时要做的动作 */
protected void onListItemClick(ListView l,View v,int position,
long id)
{
File file=new File(paths.get(position));
if (file.isDirectory())
{
/* 如果是文件夹就再运行getFileDir() */
getFileDir(paths.get(position));
}
else
{
/* 如果是文件就运行openFile() */
openFile(file);
}
}
/* 在手机上打开文件的方法 */
private void openFile(File f)
{
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
/* 调用getMIMEType()来取得MimeType */
String type = getMIMEType(f);
/* 设置intent的file与MimeType */
intent.setDataAndType(Uri.fromFile(f),type);
startActivity(intent);
}
/* 判断文件MimeType的方法 */
private String getMIMEType(File f)
{
String type="";
String fName=f.getName();
/* 取得扩展名 */
String end=fName.substring(fName.lastIndexOf(".")+1,
fName.length()).toLowerCase();
/* 依附档名的类型决定MimeType */
if(end.equals("m4a")||end.equals("mp3")||end.equals("mid")
||end.equals("xmf")||end.equals("ogg")||end.equals("wav"))
{
type = "audio";
}
else if(end.equals("3gp")||end.equals("mp4"))
{
type = "video";
}
else if(end.equals("jpg")||end.equals("gif")||end.equals("png")
||end.equals("jpeg")||end.equals("bmp"))
{
type = "image";
}
else
{
/* 如果无法直接打开,就跳出软件列表给用户选择 */
type="*";
}
type += "/*";
return type;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android iconFile带图标的文件资源管理器.zip
共30个文件
class:9个
png:7个
xml:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 87 浏览量
2022-06-14
15:04:15
上传
评论
收藏 90KB ZIP 举报
温馨提示
Android iconFile带图标的文件资源管理器.zip
资源推荐
资源详情
资源评论
收起资源包目录
Android iconFile带图标的文件资源管理器.zip (30个子文件)
Android iconFile带图标的文件资源管理器
iconFile带图标的文件资源管理器
bin
classes.dex 7KB
com
test
R$layout.class 396B
R$id.class 409B
R$drawable.class 573B
R$attr.class 310B
R.class 461B
Main.class 4KB
R$string.class 397B
MyAdapter.class 3KB
MyAdapter$ViewHolder.class 647B
resources.ap_ 18KB
iconFile.apk 23KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
folder.png 4KB
back01.png 4KB
doc.png 4KB
back02.png 4KB
icon.png 4KB
values
strings.xml 186B
color.xml 201B
drawable-mdpi
icon.png 3KB
layout
file_row.xml 627B
main.xml 658B
assets
default.properties 449B
gen
com
test
R.java 1KB
src
com
test
MyAdapter.java 3KB
Main.java 3KB
.project 844B
.classpath 280B
AndroidManifest.xml 667B
共 30 条
- 1
资源评论
BryanDing
- 粉丝: 299
- 资源: 5584
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功