FileItemHelper.java 文件源码

java
阅读 39 收藏 0 点赞 0 评论 0

项目:android-slideshow 作者:
/**
 * Returns the mime type of the given item.
 */
public String getImageMimeType(FileItem item){
    String mime = "";
    try {
        mime = URLConnection.guessContentTypeFromName(item.getPath());
    } catch (StringIndexOutOfBoundsException e){
        // Not sure the cause of this issue but it occurred on production so handling as blank mime.
    }

    if (mime == null || mime.isEmpty()){
        // Test mime type by loading the image
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(item.getPath(), opt);
        mime = opt.outMimeType;
    }

    return mime;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号