Home » » File type checking for HelloGallery

File type checking for HelloGallery

Written By MR HARI on Rabu, 02 September 2009 | 08.51

In the previous article, HelloGallery, read picture files from SD, using File ArrayList, the application view all files, no matter what type it is. Here, add a conditional checking for file type, by checking on the extension. Only files with extension jpg, gif and png will be added in the File ArrayList. Such change involve modification of the method ReadSDCard() only.


private List<String> ReadSDCard()
{
List<String> tFileList = new ArrayList<String>();

//It have to be matched with the directory in SDCard
File f = new File("/sdcard/pictures/");

File[] files=f.listFiles();

for(int i=0; i<files.length; i++)
{
File file = files[i];

String curFile=file.getPath();
String ext=curFile.substring(curFile.lastIndexOf(".")+1,
curFile.length()).toLowerCase();
if(ext.equals("jpg")||ext.equals("gif")||ext.equals("png"))
tFileList.add(file.getPath());
}

return tFileList;
}


Next >> HelloGallery, get and display the path of selected picture
Share this article :

0 komentar:

Posting Komentar

 
Support : Your Link | Your Link | Your Link
Copyright © 2013. Android Center - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger