Search code examples
androidgoogle-maps-android-api-2android-versionsupportmapfragment

Load Google Maps Android API version based on Android platform


I have an Android application that runs Google Maps API v2. By using SupportMapFragment, I support devices running Android as back as API 8. I know Google Maps API v1 is deprecated and that very few devices run Android API 7 or lower, but is there an easy way to define my layout such that for devices lower than API 8, Google Maps API v1 will be loaded?


Solution

  • I would simply suggest creating a separate Activity for API v2 and doing something like this in Activity that starts maps:

    if (isGles20() && isApi8()) {
        startNewActivity();
    } else {
        startOldActivity();
    }
    

    You will get some duplicated code, but that's what refacoring is for to extract common logic into some class.