public static String createUniqueFilename(@NonNull final String requestedName, @NonNull final List<String> existingNames, @Nullable final File dir) {

        //split in suffix and praefix
        final int suffIdx = requestedName.lastIndexOf(".");
        final String suffix = suffIdx >= 0 ? requestedName.substring(suffIdx) : "";
        final String praefix = suffIdx >= 0 ? requestedName.substring(0, suffIdx) : requestedName;

        String newPraefix = praefix;
        int idx = 1;
        while (existingNames.contains(newPraefix + suffix) || (dir != null && dir.isDirectory() && new File(dir, newPraefix + suffix).exists())) {
            newPraefix = praefix + " (" + (idx++) + ")";
        }
        return newPraefix + suffix;
    }
Create a unique non existing file named like the given file name. If a file with the given name already exists,
add a number as suffix to the file name.<br>
Example: For the file name "file.ext" this will return the first file of the list
<ul>
<li>file.ext</li>
<li>file_2.ext</li>
<li>file_3.ext</li>
</ul>
which does not yet exist.
main/src/main/java/cgeo/geocaching/utils/FileUtils.java