private String guessMimeTypeFor(final String filename) {

        if (StringUtils.isBlank(filename)) {
            return "";
        }

        //Note that when passing a wrong mimeType (not fitting to filename suffix),
        //then most document providers will append the mimeType's default extension
        //we want to avoid this from happening

        //Android SDK21/22 replace file suffixes with their defaults from mimeType.
        //This leads to e.g. "image.jpg" to be renamed to "image.jpeg".
        //->prevent this by using octet-stream for all files
        if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
            return "application/octet-stream";
        }

        //try guess mimeType from filename suffix;
        String suffix = filename;
        final int idx = filename.lastIndexOf(".");
        if (idx >= 0) {
            suffix = suffix.substring(idx + 1);
        }
        final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix);
        if (mime != null) {
            return mime;
        }

        //special handling of c:geo special files
        if ("map".equals(suffix)) {
            return "application/octet-stream";
        }
        if ("gpx".equals(suffix)) {
            //you might be thinking that here "application/xml" or "text/xml" should be returned
            //but this is not advisable since it would lead Android to append ".xml" to the filename
            //(would result in filenames like "export.gpx.xml")
            return "application/octet-stream";
        }


        //as a last resort, return empty string. This seems to work for most of the document providers and API levels
        //(tested for standard doc provider in APi levels 21,23, 29 and 30. Null triggers an exception in API21)
        //Noteable exception: "" will trigger exception with "Download" folder provider when the "Download" folder itself is selected.
        //In this case, ONLY real mime type will help unfortunately. See issue #9903
        return "";
    }
method tested on SDK21, 23, 29 and 30; both with targetSDK=29 and targetSDk=30
main/src/main/java/cgeo/geocaching/storage/DocumentContentAccessor.java