This is another way to get the targetSdkVersion my application at runtime using Android Studio :
try { PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); int targetSdkVersion = packageInfo.applicationInfo.targetSdkVersion; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, e.getMessage()); }
targetSdkVersion value targetSdkVersion defined in build.gradle file
defaultConfig { applicationId "com.tuna.hello.androidstudioapplication" minSdkVersion 9 targetSdkVersion 22 versionCode 12 versionName "1.0" }
source share