What characters allowed in file names on Android?

  1. On Android (at least by default) the file names encoded as UTF-8.

  2. Looks like reserved file name characters depend on filesystem mounted (http://en.wikipedia.org/wiki/Filename).

I considered as reserved:

private static final String ReservedChars = "|\\?*<\":>+[]/'";

According to wiki and assuming that you are using external data storage which has FAT32.

Allowable characters in directory entries

are

Any byte except for values 0-31, 127 (DEL) and: " * / : < > ? \ | + , . ; = [] (lowcase a-z are stored as A-Z). With VFAT LFN any Unicode except NUL


final String[] ReservedChars = {"|", "\\", "?", "*", "<", "\"", ":", ">"};

for(String c :ReservedChars){
    System.out.println(dd.indexOf(c));
    dd.indexOf(c);
}

From android.os.FileUtils

    private static boolean isValidFatFilenameChar(char c) {
        if ((0x00 <= c && c <= 0x1f)) {
            return false;
        }
        switch (c) {
            case '"':
            case '*':
            case '/':
            case ':':
            case '<':
            case '>':
            case '?':
            case '\\':
            case '|':
            case 0x7F:
                return false;
            default:
                return true;
        }
    }
    private static boolean isValidExtFilenameChar(char c) {
        switch (c) {
            case '\0':
            case '/':
                return false;
            default:
                return true;
        }
    }

Note: FileUtils are hidden APIs (not for apps; for AOSP usage). Use as a reference (or by reflection at one's own risk)


This is correct InputFilter for File Names in Android:

    InputFilter filter = new InputFilter()
    {
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) 
        { 
            if (source.length() < 1) return null;
            char last = source.charAt(source.length() - 1);
            String reservedChars = "?:\"*|/\\<>";
            if(reservedChars.indexOf(last) > -1) return source.subSequence(0, source.length() - 1);
            return null;
        }  
    };