简体   繁体   中英

Android Minimum SDK Issue

I have a function that I need to use, but I need to set my minimum SDK up to 23 in order to use it. Problem is, our application runs on a lot of lower SDK devices out there in the wild. Is there any way I can setup my project to allow me to compile the application while still using a lower minimum SDK target?

最低SDK问题

I have a function that I need to use, but I need to set my minimum SDK up to 23 in order to use it.

You need to set your compileSdkVersion to 23.

Is there any way I can setup my project to allow me to compile the application while still using a lower minimum SDK target?

Set your minSdkVersion to whatever you want. Set your compileSdkVersion to 23 or higher. Then, make sure that you only call canDrawOverlays() on API Level 23+ devices, such as by checking Build.VERSION.SDK_INT .

Check that the api is 23 or greater before trying to call this function:

if (android.os.Build.VERSION.SDK_INT >= 23) {
    Settings.canDrawOverlays(this);
} else {
// I don't think you need to do anything, I believe canDrawOverlays is 
//functionally true for older APIs
}

Have you already had a look at the Supporting Different Platform Versions page?

If you want to use the method canDrawOverlays(...) on ALL platforms, then you simply can't: it's only supported in the API starting from version 23. However, if you want to use this api ONLY when the platform version >= 23 (meaning: only on those devices with AT LEAST Marshmallow installed), then you can:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.MARSHMALLOW) {
    Settings.canDrawOverlays(...)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM