Author Topic: File Extension Filter  (Read 1778 times)

Offline xperia64

  • Moderator
  • double
  • *****
  • Posts: 591
    • View Profile
    • My Apps
File Extension Filter
« on: February 19, 2012, 08:17:13 PM »
While going through your FileChooserActivity.java to see what i could add to mine, I noticed a little error that leads to a crash. I notice your code checks the last three letters of an extension. I made a file with a .n6 extension and it showed up in the browser. This also happens with a file with named something like Gamen64  Tapping either will lead to a crash. Here is a solution to ensure that only real n64 extensions are found.
Code: [Select]
int dotPosition = filename.lastIndexOf("."); // Find the .
if (dotPosition != -1) // Make sure there is an extension
{
ext = (filename.substring(dotPosition)).toLowerCase();
if( extensions.contains( ext ) )
files.add( new MenuOption( filename, "File Size: " + file.length(), file.getAbsolutePath() ) );
}