Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"deprecated" vs "Field requires API level 30 (current min is 21)"

If I write:

bmp.compress(Bitmap.CompressFormat.WEBP_LOSSLESS, 80, image)

Android Studio shows an error message:

Field requires API level 30 (current min is 21)
And if I write:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

bmp.compress(Bitmap.CompressFormat.WEBP, 80, image)

says:

WEBP is deprecated. Deprecated in Java.

Should I do this?:

if(android.os.Build.VERSION.SDK_INT >= 30) {
    bmp.compress(Bitmap.CompressFormat.WEBP_LOSSLESS, 80, image)
}else{
    bmp.compress(Bitmap.CompressFormat.WEBP, 80, image)
}

In this case, the target SDK that we have defined in Android Studio does not interfere with this code?

>Solution :

Yes, that’s exactly what you have to, unfortunately. Android studio won’t complain or interfere.

There are lots of questions that involve the exact same block that you wrote, for example in the answers to How to deal with deprecated classes in Android to keep compatibility

Once you drop support for Android versions below API level 30, you can remove this block.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading