Added a function to get the current Android SDK version at runtime
authorSam Lantinga <slouken@libsdl.org>
Thu, 23 May 2019 14:19:00 -0700
changeset 127564116bf232fe7
parent 12755 8385c930c2d0
child 12757 96bca5da4965
Added a function to get the current Android SDK version at runtime
src/core/android/SDL_android.c
src/core/android/SDL_android.h
     1.1 --- a/src/core/android/SDL_android.c	Thu May 23 13:47:30 2019 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Thu May 23 14:19:00 2019 -0700
     1.3 @@ -42,6 +42,7 @@
     1.4  #include "../../haptic/android/SDL_syshaptic_c.h"
     1.5  
     1.6  #include <android/log.h>
     1.7 +#include <sys/system_properties.h>
     1.8  #include <pthread.h>
     1.9  #include <sys/types.h>
    1.10  #include <unistd.h>
    1.11 @@ -2406,6 +2407,18 @@
    1.12      return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
    1.13  }
    1.14  
    1.15 +int SDL_GetAndroidSDKVersion(void)
    1.16 +{
    1.17 +    static int sdk_version;
    1.18 +    if (!sdk_version) {
    1.19 +        char sdk[PROP_VALUE_MAX] = {0};
    1.20 +        if (__system_property_get("ro.build.version.sdk", sdk) != 0) {
    1.21 +            sdk_version = SDL_atoi(sdk);
    1.22 +        }
    1.23 +    }
    1.24 +    return sdk_version;
    1.25 +}
    1.26 +
    1.27  SDL_bool SDL_IsAndroidTablet(void)
    1.28  {
    1.29      JNIEnv *env = Android_JNI_GetEnv();
     2.1 --- a/src/core/android/SDL_android.h	Thu May 23 13:47:30 2019 -0700
     2.2 +++ b/src/core/android/SDL_android.h	Thu May 23 14:19:00 2019 -0700
     2.3 @@ -122,6 +122,8 @@
     2.4  SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled);
     2.5  
     2.6  
     2.7 +int SDL_GetAndroidSDKVersion(void);
     2.8 +
     2.9  SDL_bool SDL_IsAndroidTablet(void);
    2.10  SDL_bool SDL_IsAndroidTV(void);
    2.11  SDL_bool SDL_IsChromebook(void);