5
\$\begingroup\$

I want to separate code to run only on android 4.4 or higher. If it's lower, I do not want to run this code. What should I do?

\$\endgroup\$
2
\$\begingroup\$

You can check SystemInfo.operatingSystem. The string should contain both OS name and version. Never tried on Android but should work.

\$\endgroup\$
2
\$\begingroup\$

A ready to use method which is better than SystemInfo.operatingSystem :

public int GetSDKLevel() {
    var clazz = AndroidJNI.FindClass("android.os.Build$VERSION");
    var fieldID = AndroidJNI.GetStaticFieldID(clazz, "SDK_INT", "I");
    var sdkLevel = AndroidJNI.GetStaticIntField(clazz, fieldID);
    return sdkLevel;
}

Just copy and paste and that's all.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.