private static boolean isExtendedWebpSupported ( ) { // Lossless and extended formats are supported on Android 4.2.1+ // Unfortunately SDK_INT is not enough to distinguish 4.2 and 4.2.1 // (both are API level 17 (JELLY_BEAN_MR1)) if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . JELLY_BEAN_MR1 ) { return false ; } if ( Build . VERSION . SDK_INT == Build . VERSION_CODES . JELLY_BEAN_MR1 ) { // Let's test if extended webp is supported // To this end we will try to decode bounds of vp8x webp with alpha channel byte [ ] decodedBytes = Base64 . decode ( VP8X_WEBP_BASE64 , Base64 . DEFAULT ) ; BitmapFactory . Options opts = new BitmapFactory . Options ( ) ; opts . inJustDecodeBounds = true ; BitmapFactory . decodeByteArray ( decodedBytes , 0 , decodedBytes . length , opts ) ; // If Android managed to find appropriate decoder then opts.outHeight and opts.outWidth // should be set. We can not assume that outMimeType is set. // Android guys forgot to update logic for mime types when they introduced support for webp. // For example, on 4.2.2 this field is not set for webp images. if ( opts . outHeight != 1 || opts . outWidth != 1 ) { return false ; } } return true ; }
Checks whether underlying platform supports extended WebPs