Android: should I use MimeTypeMap.getFileExtensionFromUrl()? [bugs]

前端 未结 3 1019
情歌与酒
情歌与酒 2021-02-20 06:48

For example, I wanted to get the file Extension from the file URL using the function below:

File name:

Greatest Hits - Lenny Kravitz (Booklet 01) [2000]         


        
3条回答
  •  不要未来只要你来
    2021-02-20 07:32

    private String getMimeTypeFromPath(String path) { 
        String extension = path; 
        int lastDot = extension.lastIndexOf('.'); 
        if (lastDot != -1) { 
            extension = extension.substring(lastDot + 1); 
        } 
        // Convert the URI string to lower case to ensure compatibility with MimeTypeMap (see CB-2185). 
        extension = extension.toLowerCase(Locale.getDefault()); 
        if (extension.equals("3ga")) { 
            return "audio/3gpp"; 
        } else if (extension.equals("js")) { 
            // Missing from the map :(. 
            return "text/javascript"; 
        } 
        return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); 
    } 
    

提交回复
热议问题