androidandroid-manifestandroid-4.0-ice-cream-sandwichmultiple-versionsandroid-min-sdk

Change minSDKVersion depending on Device


I want to publish my application for more than one Version of Android. Thats why I wrote this in my Manifest xml

<uses-sdk android:minSdkVersion="8" />

My app shows a TimePicker. The TimePicker usually looks different in version 4.0.3. Since I choose version 8 as my default sdk version, the TimePicker looks like the old one, even then I run the app on a 4.0.3 device.

Is there any way to choose sdk version 15 when this app is running on a 4.0.3 device?


Solution

  • Your apk is only compiled once, so no. Instead, you should set in your AndroidManifest.xml,

    <uses-sdk android:minSdkVersion="8" 
        android:targetSdkVersion="15" />
    

    and then check in your code (at runtime) that old devices don't make use of the methods provided in the new framework. For instance,

    int currentVersion = android.os.Build.VERSION.SDK_INT;  
    if (currentVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        // It is safe to use the TimePicker.
    } else{
        // Don't use the TimePicker (ClassNotFoundException will be thrown).
    }