To do this we need to get the root directory of the external storage directory, i.e SDcard.
File f = new File("/sdcard");
private List<String> item = new ArrayList<String>();
private List<String> path = new ArrayList<String>();
getFiles(f);
The getFiles(..) method retrieves the all files from the sdcard and stores
private void getFiles(File f)
{
File[] files=f.listFiles();
for (int i = 0; i < files.length; i++)
{
try{
if (files[i].isDirectory()) {
getFiles(files[i]);
}
else
{
if (files[i].isFile() ) {
if(files[i].getParent().equals("/sdcard/DCIM/.thumbnails"))
continue;
String test=files[i].getName().toLowerCase();
if(test.endsWith(".mp3")||test.endsWith(".mp4")||test.endsWith(".3gp")||test.endsWith(".wav")||test.endsWith("flac")||test.endsWith("xmf")||test.endsWith("ota"))
{
path.add(files[i].getPath());
item.add(files[i].getName());
}
}
}
}catch(Exception e){
e.getMessage();
}
}
}//get files
File f = new File("/sdcard");
private List<String> item = new ArrayList<String>();
private List<String> path = new ArrayList<String>();
getFiles(f);
The getFiles(..) method retrieves the all files from the sdcard and stores
private void getFiles(File f)
{
File[] files=f.listFiles();
for (int i = 0; i < files.length; i++)
{
try{
if (files[i].isDirectory()) {
getFiles(files[i]);
}
else
{
if (files[i].isFile() ) {
if(files[i].getParent().equals("/sdcard/DCIM/.thumbnails"))
continue;
String test=files[i].getName().toLowerCase();
if(test.endsWith(".mp3")||test.endsWith(".mp4")||test.endsWith(".3gp")||test.endsWith(".wav")||test.endsWith("flac")||test.endsWith("xmf")||test.endsWith("ota"))
{
path.add(files[i].getPath());
item.add(files[i].getName());
}
}
}
}catch(Exception e){
e.getMessage();
}
}
}//get files
No comments:
Post a Comment