Search code examples
androidbackwards-compatibility

Is it Possible? app developed in 2.x device with compatibility lib V4 to use native library if device is android 3.x or greater device?


Before posting my question. i looked this one stack overflow.and wann know, is it really impossible? i have app developed in android 2.2 with the use of compatibility library v4. which is also compatible with android 3.0 device. and i want my app to use android compatibility library v4 if device is android 2.x and native library if device is android 3.x. any suggestion??

thanks in advance


Solution

  • I haven't tried what I'm recommending, but it could work:

    1. Set your build target to Honeycomb
    2. Use an if-else statement and Build info to determine which version of Android you're on
    3. If you're below 3.0, use the compatibility library in your code
    4. If you're on 3.0 or above, use the native library.

    For this to work, you'll need to use fully qualified names in your code, instead of having import statements on the top. So for Fragments on 3.0 and above, you'd use:

    android.app.Fragment fragment;
    

    instead of:

    Fragment fragment;
    

    and an import statement on top. And finally for pre 3.0, you'd need statements like:

    android.support.v4.app.Fragment fragment;
    

    You need to use these names as you cannot import both version and use only one.