s.d
s.d

Reputation: 29436

Find correct android version on device

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD) {
        //--incompatible code--
    } else {
        //--compatible code--
    }

The condition runs into incompatible code on Gingerbread. Does Build.VERSION.SDK_INT represents actual device version ? or the SDK version the app has been compiled with ?

Upvotes: 0

Views: 174

Answers (2)

pansz
pansz

Reputation: 170

This is a static member, which was assigned value when the app first executes.

public static final int SDK_INT = SystemProperties.getInt("ro.build.version.sdk", 0);

The SystemProperties.getInt() member function runs on your target device and is not determined when you compile your application.

According to the official guide you should use >= instead of > when detect api version, i.e.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

since there may be minor versions between major versions.

Upvotes: 2

s.d
s.d

Reputation: 29436

The issue was that there are 2 codes for GB:

Build.VERSION_CODES.GINGERBREAD -> API 9

and

Build.VERSION_CODES.GINGERBREAD_MR1 -> API 10

as minSdkVersion API in manifest = 10 then I should have used Build.VERSION_CODES.GINGERBREAD_MR1.

Upvotes: 1

Related Questions