Android: Add convenience function to get the API level.
It's common to check the Android API level at runtime to determine what functionality is available. This change provides a convenient way to get the Android SDK version (API level) from c++. Change-Id: I88f65ae87e0fa8ac0affefffbd1b1bba855c9f46 Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
parent
fd22e89593
commit
48db373ce3
@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE
|
||||
static JavaVM *g_javaVM = Q_NULLPTR;
|
||||
static jobject g_jActivity = Q_NULLPTR;
|
||||
static jobject g_jClassLoader = Q_NULLPTR;
|
||||
static jint g_androidSdkVersion = 0;
|
||||
|
||||
static inline bool exceptionCheck(JNIEnv *env)
|
||||
{
|
||||
@ -60,6 +61,19 @@ static inline bool exceptionCheck(JNIEnv *env)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void setAndroidSdkVersion(JNIEnv *env)
|
||||
{
|
||||
jclass androidVersionClass = env->FindClass("android/os/Build$VERSION");
|
||||
if (exceptionCheck(env))
|
||||
return;
|
||||
|
||||
jfieldID androidSDKFieldID = env->GetStaticFieldID(androidVersionClass, "SDK_INT", "I");
|
||||
if (exceptionCheck(env))
|
||||
return;
|
||||
|
||||
g_androidSdkVersion = env->GetStaticIntField(androidVersionClass, androidSDKFieldID);
|
||||
}
|
||||
|
||||
jint QtAndroidPrivate::initJNI(JavaVM *vm, JNIEnv *env)
|
||||
{
|
||||
jclass jQtNative = env->FindClass("org/qtproject/qt5/android/QtNative");
|
||||
@ -93,6 +107,8 @@ jint QtAndroidPrivate::initJNI(JavaVM *vm, JNIEnv *env)
|
||||
if (exceptionCheck(env))
|
||||
return JNI_ERR;
|
||||
|
||||
setAndroidSdkVersion(env);
|
||||
|
||||
g_jClassLoader = env->NewGlobalRef(classLoader);
|
||||
env->DeleteLocalRef(classLoader);
|
||||
g_jActivity = env->NewGlobalRef(activity);
|
||||
@ -118,4 +134,9 @@ jobject QtAndroidPrivate::classLoader()
|
||||
return g_jClassLoader;
|
||||
}
|
||||
|
||||
jint QtAndroidPrivate::androidSdkVersion()
|
||||
{
|
||||
return g_androidSdkVersion;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -64,6 +64,7 @@ namespace QtAndroidPrivate
|
||||
Q_CORE_EXPORT JavaVM *javaVM();
|
||||
Q_CORE_EXPORT jint initJNI(JavaVM *vm, JNIEnv *env);
|
||||
jobject classLoader();
|
||||
jint androidSdkVersion();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user