Android檔案瀏覽器的開發

來源:互聯網
上載者:User

裡面有詳細的檔案瀏覽原始碼。大家可以參考下。
/m.d1{%zR5GiM3不過可惜就是沒有檔案相關操作,我用了下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;3GEYEc0nQ;`/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~HYT*W
        fill(new File("/").listFiles());
FH3b[2P0F$q3    }3GEYE:q#^Q$mn`6p
   
W``ASiq0M3    @Override
T_-Rr#gV!b3    protected void onListItemClick(ListView l, View v, int position, long id) {3GEYEw2uF+P5p�s
        int selectionRowID = (int) getSelectionRowID();3GEYENmDuc d;]L
        if (selectionRowID == 0) {3GEYEb|9ue:~5n
            fillWithRoot();
/ lM5]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.u3Gpu5S
                AlertDialog.show(this, "Not a Directory",3GEYE VZ*?/a4{,r
                        "That's a file, not a directory", "Cancel", false);
;Tt)L}+mZ7VcUn$ch3        }
dvCn_F-k2Na3    }
5XZSd,ne3
k QUs@p3X H-[3    private void fillWithRoot() {
'N+S)P&|#m3        fill(new File("/").listFiles());3GEYEL/o](_.Dl/P
    }
"EC'MeUrG3
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));3GEYEO"`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/zi I
    }3GEYE[O*~ S+G-C#L
}3GEYELG$j@C

9A%ZB'w+q `fu3/* AUTO-GENERATED FILE.  DO NOT MODIFY.3GEYEg�NZgGp: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"njE-n
    }
#|uP6ocdQ3    public static final class drawable {3GEYEi(q~:JgzU/D`2D
        public static final int icon=0x7f020000;
htZOq6[E[3    }3GEYE5Wc:R5JV*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 {
0sc Wj,q3        public static final int app_name=0x7f040000;3GEYEQEX_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,大家可以把資料儲存到這裡

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.