Thinking in XiaoQiang
世人皆有悲哀,只有你不明白
posts - 56,comments - 150,trackbacks - 0
G1上并没有随系统附带文件浏览软件, 考虑到电子书,媒体播放器或其它一些软件会使用到文件浏览,选择文件或文件夹, 所以先做了这个文件管理工具并封装一些参数供第三方程序调用,可以做为插件形式使用
把文件管理器封装起来并使用intent机制设置浏览参数和调用
目前暂不支持多文件选择, 将在下一版中发布
调用程序示例

1          Button button2 = (Button) findViewById(R.id.but2);
2          button2.setOnClickListener(testFileManager);

 1 private OnClickListener testFileManager = new OnClickListener() {
 2         public void onClick(View v) {
 3             Intent intent = new Intent("net.uiiang.android.alkaid.FILEMANAGER");
 4             
 5             //参数root_directory, 设置浏览的根目录, 例如设置/sdcard则只允许程序浏览sd卡中的内容, 当程序回退上层文件夹到/sdcard后不再向上回退
 6             //参数类型为字符串, 默认为"/"(根目录)
 7             intent.putExtra("root_directory""/");
 8             
 9             //参数exclude_directory, 设置不显示的目录, 例如设置"/data", "/dev", 则"/data", "/dev"这两个目录不会显示给用户
10             //参数类型为字符串数组, 默认不排除任何文件夹
11             intent.putExtra("exclude_directory",
12                     new String[] { "/data""/dev" });
13 
14             //参数thrid_party_call, 当第三方程序调用时, 必须设置此参数为true, 否则下面几个参数不起作用
15             //参数类型为boolean, 默认为false, 会显示以下参数可设置的所有菜单(除 选择菜单)
16             intent.putExtra("thrid_party_call"true
);
17             
18             // 参数directory_show_type, 目录浏览方式
19             // 参数类型为 int, 默认为0
20             // 0 : 显示文件和文件夹(默认)
21             // 1 : 只显示文件
22             // 3 : 只显示文件夹 
23             intent.putExtra("directory_show_type"0);
24             
25             //参数use_menu_items, 设置显示的预置菜单
26             //参数类型为:int数组
27             //菜单列表:
28             // 1 : 上下文菜单-打开  (文件夹)
29             // 2 : 上下文菜单-删除
30             // 3 : 上下文菜单-详细信息
31             // 4 : 上下文菜单-复制
32             // 5 : option菜单-粘贴
33             // 6 : option菜单-新建文件夹
34             // 99: 上下文菜单-选择 , 若需要文件管理器返回一个选中的文件路径, 则必须设置此菜单
35             // 当用户点击此菜单后, 文件管理器退出并返回给调用程序一个字符串数组, 数组中包含文件路径信息
36             intent.putExtra("use_menu_items"new int[] { 99 });
37             
38             // 参数show_info_in_list, 是否在浏览文件中显示简单的信息, 如文件夹中包含多少子文件夹和文件
39             // 默认为true
40             intent.putExtra("show_info_in_list"false);
41             
42             // 参数show_file_extension, 是否显示文件后缀名
43             // 默认为 true
44             intent.putExtra("show_file_extension"false);
45             
46             // 参数use_simple_view, 是否使用简单文件预览
47             // 用户单击文件后可以简单的预览文件内容, 目前支持图片和音乐文件
48             // 默认为 true
49             intent.putExtra("use_simple_view"false);
50             
51             // 参数animation_show_list, 是否使用动态效果显示文件列表, 目前只支持向下卷帘式的效果
52             // 默认为true
53             intent.putExtra("animation_show_list"true);
54             
55             //参数mutiple_select, 是否支持多选, 为true可以一次性选择多个文件或目录
56             //默认为false
57             intent.putExtra("mutiple_select",false);
58 
59             startActivityForResult(intent, SELECT_FILE);
60         }
61     };



通过startActivityForResult调用文件管理器, 并使用上下文菜单选择文件或文件夹



点击"选择"后, 返回到调用程序
 1     @Override
 2     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 3         super.onActivityResult(requestCode, resultCode, data);
 4         if (requestCode == SELECT_FILE) {
 5             if (resultCode == RESULT_OK) {
 6                 // 参数名为selected_uri, 得到字符串数组中包含文件路径
 7                 String[] selectArr = data.getExtras().getStringArray(
 8                         "selected_uri");
 9                 if (selectArr != null) {
10                     String selectFile = "";
11                     for (String string : selectArr) {
12                         System.out.println("you select  = "
13                                 + data.getExtras().getStringArray(
14                                         "selected_uri"));
15                     }
16                 }
17 
18             }
19         }
20     }

posted on 2009-10-17 20:21 小强 阅读(2644) 评论(2)  编辑  收藏 所属分类: google-android

FeedBack:
# re: android小应用 文件管理器 V0.1 第三方调用方法备忘
2009-10-18 20:24 | 99书城
好东西啊!  回复  更多评论
  
# re: android小应用 文件管理器 V0.1 第三方调用方法备忘
2009-10-20 03:26 | 美容
android小应用 good  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: