태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

package com.kei.fileexplorer;

import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;
import android.widget.Toast;

public class FileExplorer extends Activity {
 
 String mSdPath ="";
 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        String result = new String("");     
        TextView tv = (TextView)findViewById(R.id.text1);
       
        String ext = Environment.getExternalStorageState();

        if(ext.equals(Environment.MEDIA_MOUNTED)) {
         mSdPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        } else {
         mSdPath = Environment.MEDIA_UNMOUNTED;
        }
       
        try{    
           File f = new File(mSdPath);
          
           String[] filenames = f.list(null);
          
           for (int i = 0; i < filenames.length ; i++){
            String filename = filenames[i];
            if (filename.toLowerCase().endsWith("jpg")) {
             result = result + filename + "\n";
            }
           }  
           
           tv.setText(result);
           
           }catch(Exception e){  
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();  
           }
    }
   
}

+ Recent posts