user486646
user486646

Reputation:

Is it possible to read the minSDKVersion from AndroidManifest at runtime?

I understand what the difference is between the different versions and how to set them, I just want to know if I can actually read the minimum API level at runtime. Target API is available in ApplicationInfo, but not minimum.

I am making a library to be used for apps that can make things much more convenient if the app is used on API 14 and above, but for pre-14 the user of the library will have to do things manually. I want to base enabling of the feature on what the minimum SDK specified was. If I know the minimum was at least 14 then I can enable the feature and the user does not have to include the manual code.

I don't want to base it on the actual version of the device, because if I do that and the user is allowing to run on lower than 14 then he will have to surround the manual code with a check to see if he needs to do it

Upvotes: 0

Views: 256

Answers (2)

Guillaume Perrot
Guillaume Perrot

Reputation: 4308

It seems to be possible only in API Level 24: https://developer.android.com/reference/android/content/pm/ApplicationInfo.html#minSdkVersion (context.getApplicationInfo).

If you are not writing a library, you can inject it in the BuildConfig in your application gradle script to be able to read the value on older devices: https://stackoverflow.com/a/37555584/598520

Thus, this question duplicates How to get minimum sdk version(minSdkVersion) at runtime?

Upvotes: 2

kiturk3
kiturk3

Reputation: 558

you can make functions differently with help of

int crntVer = android.os.Build.VERSION.SDK_INT;

if (crntVer >= android.os.Build.VERSION_CODES.LOLLIPOP)
{ 
           // do something for lollipop
}
else
{
          //do something for previous version...
}

Upvotes: -1

Related Questions