论坛首页 移动开发技术论坛

Android文件浏览器的开发

浏览 4889 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-02-17  

里面有详细的文件浏览源代码。大家可以参考下。
/m.d1{%zR5G iM3不过可惜就是没有文件相关操作,我用了下File,不过对于createNewFile, mkdir等不成功,不知道是什么原因。3GEYE$`i#kN-n#@/TO
3GEYE1X)ka,w3QI.}
具体看源代码吧。
:k*kK)py2X"_33GEYE(T6wxO gE/S4sL,c
package org.lombardos.android.FSExplorer1;
xscB/FaL3
/}]2j"PlbUy3import java.io.File;3GEYEO {|QN@
import java.util.ArrayList;3GEYEc0n Q;`/Y a
import java.util.List;
%}0@/yi!A3
^0KK8`c,Ke"c$|3import android.app.AlertDialog;3GEYE%y Z0C$q~hPY(i
import android.app.ListActivity;3GEYE7U0v�U-sY$p;wMb
import android.os.Bundle;3GEYE8TW-N7|4x
import android.view.View;
8W@4o$n,\3import android.widget.ArrayAdapter;
Ex,dKx)|TG9h3import android.widget.ListView;
_u)l0CMe:y3
"e@?0p#NP3public class FileList extends ListActivity {3GEYE[ }+Ol8|$zd0fz
   
'\x$A.x}3v+{s6Z-s7o3    private List<String> items = null;
2o!SI6?#@Q3
5pU*yGm~b1F3    /** Called when the activity is first created. */
cSjBr3    @Override3GEYE2]3?GT&p0r/y
    public void onCreate(Bundle icicle) {
7s,YG ]5TlCI _3        super.onCreate(icicle);3GEYE"G;y"WUO eH*k eW
        setContentView(R.layout.directory_list);3GEYE2MI7~H YT*W
        fill(new File("/").listFiles());
FH3b[2P0F$q3    }3GEYE:q#^Q$mn`6p
   
W``AS iq0M3    @Override
T_-Rr#gV!b3    protected void onListItemClick(ListView l, View v, int position, long id) {3GEYEw2u F+P5p�s
        int selectionRowID = (int) getSelectionRowID();3GEYENmDuc d;]L
        if (selectionRowID == 0) {3GEYEb|9ue:~5n
            fillWithRoot();
\ l M5]2K e9t_3        } else {
?\$~.p{3            File file = new File(items.get(selectionRowID));3GEYE Q&nlmO-r_
            if (file.isDirectory())
Jt4S+xo?%ze:R3                fill(file.listFiles());
W!TD�v8b7p3            else3GEYE-Yd.u3Gp u5S
                AlertDialog.show(this, "Not a Directory",3GEYE VZ*?/a4{,r
                        "That's a file, not a directory", "Cancel", false);
;Tt)L}+m Z7VcUn$ch3        }
dvCn_F-k2Na3    }
5XZSd,n e3
k QUs@p3X H-[3    private void fillWithRoot() {
'N+S)P&|#m3        fill(new File("/").listFiles());3GEYEL/o](_.D l/P
    }
"EC'MeUr G3
Tk7h1| V6A(y:M*OY3    private void fill(File[] files) {
)^R4a4Q tP%Bub3        items = new ArrayList<String>();
H5K#is"S?RdZ3        items.add(getString(R.string.to_top));3GEYE O"`tB?*?6b
        for (File file : files)
,JC] r4h3            items.add(file.getPath());
gH6hGY.?6ik3        ArrayAdapter<String> fileList = new ArrayAdapter<String>(this,3GEYE*Ty"E/HeN#C"X z
                R.layout.file_row, items);
gcf7W8pl3        setListAdapter(fileList);3GEYEnV d/z i I
    }3GEYE[O*~ S+G-C#L
}3GEYELG$j@C

9A%ZB'w+q `fu3/* AUTO-GENERATED FILE.  DO NOT MODIFY.3GEYEg�N Zg G p:ke c
 *
m^%p;P`(R3 * This class was automatically generated by the3GEYEmvuO{Jue5Qbi
 * aapt tool from the resource data it found.  It3GEYE$G&B'v{ ?z"Zx
 * should not be modified by hand.3GEYE b g._ r4H3{8^ B#F9M
 */3GEYEZTD } T1yap w

.Y[G+i7[t,~7Z#G]r3package org.lombardos.android.FSExplorer1;3GEYE C{${"[s }

}#wbLh)w3public final class R {
!Ty w)I9j&U7[e3    public static final class attr {3GEYEP0L e2Y"nj E-n
    }
#|uP6ocdQ3    public static final class drawable {3GEYEi(q~:JgzU/D`2D
        public static final int icon=0x7f020000;
htZOq6[E[3    }3GEYE5Wc:R5J V*g
    public static final class id {
'L8f%I%J"Kb,z;kX"q3        public static final int text1=0x7f050000;
"}4D s{vT}3    }
&fT.b.{h3    public static final class layout {
$cxs,|-oT5d}3        public static final int directory_list=0x7f030000;
%R)Up|r(O3R%n3        public static final int file_row=0x7f030001;3GEYE+O*Eqe)xA,L[
        public static final int main=0x7f030002;
!y4c1vokW9`3    }
%a/r*XgZ@9C4?3    public static final class string {
0s c Wj,q3        public static final int app_name=0x7f040000;3GEYEQE X _f
        public static final int no_files=0x7f040001;
Z)lG(u"VN)T3        public static final int to_top=0x7f040002;3GEYEJp*aI+a]r1R
    }3GEYE&QQaQv
}

 

顺便说下

对于File的操作需要具体的权限。

我在Data下面就不可以操作

对于tmp就可以

因为Android是采用linux系统的,所以目录结构下面应该有一个Home,大家可以把数据保存到这里

论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics