为什么filechooser没有显示所有文件夹(文件夹和文件),但显示了一些文件/文件夹?
Android Manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
FileChooser类:
public class FileChooser extends ListActivity {
private File directory;
private FileArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
directory = new File("/sdcard/");
fill(directory);
}
public void fill(File f){
File[] dirs = f.listFiles();
this.setTitle("Dir:"+f.getName());
List<Option> dir = new ArrayList<Option>();
List<Option> files = new ArrayList<Option>();
try{
for(File ff:dirs){
if(ff.isDirectory()){
dir.add(new Option(ff.getName(),"[+]Pasta ",ff.getPath()));
}else{
long size;
if(ff.length()>0){
size=ff.length()/1024;
}else{
size=ff.length();
}
files.add(new Option(ff.getName(),"Tamanho "+size+"kb",ff.getPath()));
}
}
}catch (Exception e){}
Collections.sort(dir);
Collections.sort(files);
dir.addAll(files);
if(!f.getName().equalsIgnoreCase("")){
dir.add(0,new Option("..","pasta anterior",f.getParent()));
}
adapter = new FileArrayAdapter(FileChooser.this,R.layout.activity_file_chooser,dir);
this.setListAdapter(adapter);
}
protected void onListItemClick(ListView listView, View view, int position, long id){
super.onListItemClick(listView,view,position,id);
Option o = adapter.getItems(position);
if(o.getData().equalsIgnoreCase("[+]Pasta ")||o.getData().equalsIgnoreCase("pasta anterior")){
directory = new File((o.getPath()));
fill(directory);
}else{
try {
Bundle extras = getIntent().getExtras();
String classname = extras.getString("class");
Class<?> clazz = Class.forName(classname);
Intent intent = new Intent(FileChooser.this, clazz);
intent.putExtra("path", o.getPath());
startActivity(intent);
}catch (Exception e){
Log.d(">>>>", String.valueOf(e));
}
}
}
}
模拟器上的SDFOLDER
使用filebrowser apk
SDFOLDER或/ Storage / Emulated / on Emulator(空)
用我的apk
/ sys / kernel / on Emulator
用我的apk(工作正常!)