navid ansari navid ansari - 5 months ago 16
Android Question

How can I check API version?

I want use bluetooth low energy (BLE).
In

API
lower than 21 I should use
startlescan()
and in API 21 I should use
startscan()
and its scan callback that is not for API less than 21.

how can I separate those code to have both in my app?

The error:
enter image description here

I want something like this:

if(api < 21) startlescan();
if(api >= 21) startscan();

Answer

You can use below code:-

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    startlescan();
}
else{

    startscan();
}