SDCARD内のすべての画像をそのディレクトリが存在するディレクトリで読み込もうとしています。/mnt/sdcard/album1にファイルTEST.jpgがあり、/ mnt/sdcard/album1/album2にTEST2.jpgというファイルがある場合、ディレクトリ名album1とalbum2を取得できるはずです。 私は再帰的にこれを行うコードを書いています。これは、フォルダの数が少なくてもディレクトリの数が増えるとループが出てくるときに機能します。android画像があるSDCARD内のすべてのディレクトリを読む
public void getImageFoldes(String filepath){
String albumpath;
File file = new File(filepath);
File[] files = file.listFiles();
for (int fileInList = 0; fileInList < files.length; fileInList++)
{
File filename;
filename =files[fileInList];
if(filename.isHidden()|| filename.toString().startsWith("."))
return;
if (filename.isDirectory()){
albumpath = filename.toString();
String[] split;
String title;
split= albumpath.split("/");
title=split[split.length-1];
result = new thumbnailResults();
result.setTitle(title);
result.setPath(albumpath);
result.setIsLocal(true);
//result.setCreated("05-06-2011");
getImageFoldes(filename.toString());
}
else{
if (files.length !=0)
{
//if File is the image file then store the album name
if ((files[fileInList].toString()).contains(".png")||
(files[fileInList].toString()).contains(".jpg")||
(files[fileInList].toString()).contains(".jpeg")){
if (!results.contains(result)){
result.setUri(Uri.parse(files[fileInList].getPath()));
results.add(result);
myadapter.notifyDataSetChanged();
}
}
}
}
}
}
sahoo:それは私にJPEGファイルの正確なファイルパスを与えます。私が必要とするのはディレクトリまでのパスだけです。私が1つのフォルダ/mnt/sdcard/album1/album2/test.jpgと/mnt/sdcard/album3/test1.jpgを持っていれば、私の結果は最初の値が/ man/sdcard/album1/album2である文字列のarraylistでなければならず、 2番目のエントリは/ mnt/sdcard/album3になります。なぜDCIMフォルダを検索していないのですか? – jhon