0
    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 ?

2
  • Which version would you like to be the cutoff for compatible vs. incompatible code? 2.3? 2.3.3? 3.0? Commented Nov 2, 2012 at 7:27
  • its run for me as good. that shows me comptiable. if i replace gingerbread to eclair then not comptible. Commented Nov 2, 2012 at 7:30

2 Answers 2

2

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.

1
  • Depends on what breaks the compatibility, if its exclusive to newer API then this approach is useful too. Thanks.
    – s.d
    Commented Nov 2, 2012 at 8:08
1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.